javadoc (doclint) and whitespace fixes

includes whitespace fixes as per Coding Conventions
This commit is contained in:
Ivan Masár
2016-10-31 14:34:27 +01:00
parent db1641cfa9
commit 269af71afb
384 changed files with 24482 additions and 20843 deletions

View File

@@ -72,7 +72,7 @@ import java.util.*;
public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBean
{
private static final Logger log = Logger.getLogger(SolrLoggerServiceImpl.class);
protected HttpSolrServer solr;
public static final String DATE_FORMAT_8601 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
@@ -93,18 +93,18 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
private ConfigurationService configurationService;
public static enum StatisticsType {
VIEW ("view"),
SEARCH ("search"),
SEARCH_RESULT ("search_result"),
VIEW ("view"),
SEARCH ("search"),
SEARCH_RESULT ("search_result"),
WORKFLOW("workflow");
private final String text;
private final String text;
StatisticsType(String text) {
this.text = text;
}
public String text() { return text; }
}
this.text = text;
}
public String text() { return text; }
}
protected SolrLoggerServiceImpl()
{
@@ -118,7 +118,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
log.info("solr-statistics.spidersfile:" + configurationService.getProperty("solr-statistics.spidersfile"));
log.info("solr-statistics.server:" + configurationService.getProperty("solr-statistics.server"));
log.info("usage-statistics.dbfile:" + configurationService.getProperty("usage-statistics.dbfile"));
HttpSolrServer server = null;
if (configurationService.getProperty("solr-statistics.server") != null)
@@ -149,7 +149,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
//Also add the core containing the current year !
statisticYearCores.add(server.getBaseURL().replace("http://", "").replace("https://", ""));
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}
solr = server;
@@ -207,7 +207,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
{
SolrInputDocument doc1 = getCommonSolrDoc(dspaceObject, request, currentUser);
if (doc1 == null) return;
if(dspaceObject instanceof Bitstream)
if (dspaceObject instanceof Bitstream)
{
Bitstream bit = (Bitstream) dspaceObject;
List<Bundle> bundles = bit.getBundles();
@@ -230,42 +230,42 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
catch (Exception e)
{
log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}
@Override
public void postView(DSpaceObject dspaceObject,
String ip, String userAgent, String xforwardedfor, EPerson currentUser) {
if (solr == null || locationService == null) {
return;
}
public void postView(DSpaceObject dspaceObject,
String ip, String userAgent, String xforwardedfor, EPerson currentUser) {
if (solr == null || locationService == null) {
return;
}
try {
SolrInputDocument doc1 = getCommonSolrDoc(dspaceObject, ip, userAgent, xforwardedfor,
currentUser);
if (doc1 == null)
return;
if (dspaceObject instanceof Bitstream) {
Bitstream bit = (Bitstream) dspaceObject;
List<Bundle> bundles = bit.getBundles();
for (Bundle bundle : bundles) {
doc1.addField("bundleName", bundle.getName());
}
}
try {
SolrInputDocument doc1 = getCommonSolrDoc(dspaceObject, ip, userAgent, xforwardedfor,
currentUser);
if (doc1 == null)
return;
if (dspaceObject instanceof Bitstream) {
Bitstream bit = (Bitstream) dspaceObject;
List<Bundle> bundles = bit.getBundles();
for (Bundle bundle : bundles) {
doc1.addField("bundleName", bundle.getName());
}
}
doc1.addField("statistics_type", StatisticsType.VIEW.text());
doc1.addField("statistics_type", StatisticsType.VIEW.text());
solr.add(doc1);
// commits are executed automatically using the solr autocommit
// solr.commit(false, false);
solr.add(doc1);
// commits are executed automatically using the solr autocommit
// solr.commit(false, false);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
/**
@@ -279,7 +279,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
*/
protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, HttpServletRequest request, EPerson currentUser) throws SQLException {
boolean isSpiderBot = request != null && SpiderDetector.isSpider(request);
if(isSpiderBot &&
if (isSpiderBot &&
!configurationService.getBooleanProperty("usage-statistics.logBots", true))
{
return null;
@@ -288,7 +288,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
SolrInputDocument doc1 = new SolrInputDocument();
// Save our basic info that we already have
if(request != null){
if (request != null) {
String ip = request.getRemoteAddr();
if (isUseProxies() && request.getHeader("X-Forwarded-For") != null) {
@@ -307,7 +307,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
doc1.addField("ip", ip);
//Also store the referrer
if(request.getHeader("referer") != null){
if (request.getHeader("referer") != null) {
doc1.addField("referrer", request.getHeader("referer"));
}
@@ -321,14 +321,14 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
log.info("Failed DNS Lookup for IP:" + ip);
log.debug(e.getMessage(),e);
}
if(request.getHeader("User-Agent") != null)
{
doc1.addField("userAgent", request.getHeader("User-Agent"));
}
doc1.addField("isBot",isSpiderBot);
if (request.getHeader("User-Agent") != null)
{
doc1.addField("userAgent", request.getHeader("User-Agent"));
}
doc1.addField("isBot",isSpiderBot);
// Save the location information if valid, save the event without
// location information if not valid
if(locationService != null)
if (locationService != null)
{
Location location = locationService.getLocation(ip);
if (location != null
@@ -356,7 +356,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
}
if(dspaceObject != null){
if (dspaceObject != null) {
doc1.addField("id", dspaceObject.getID());
doc1.addField("type", dspaceObject.getType());
storeParents(doc1, dspaceObject);
@@ -373,7 +373,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
protected SolrInputDocument getCommonSolrDoc(DSpaceObject dspaceObject, String ip, String userAgent, String xforwardedfor, EPerson currentUser) throws SQLException {
boolean isSpiderBot = SpiderDetector.isSpider(ip);
if(isSpiderBot &&
if (isSpiderBot &&
!configurationService.getBooleanProperty("usage-statistics.logBots", true))
{
return null;
@@ -407,14 +407,14 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
log.info("Failed DNS Lookup for IP:" + ip);
log.debug(e.getMessage(),e);
}
if(userAgent != null)
{
doc1.addField("userAgent", userAgent);
}
doc1.addField("isBot",isSpiderBot);
if (userAgent != null)
{
doc1.addField("userAgent", userAgent);
}
doc1.addField("isBot",isSpiderBot);
// Save the location information if valid, save the event without
// location information if not valid
if(locationService != null)
if (locationService != null)
{
Location location = locationService.getLocation(ip);
if (location != null
@@ -442,7 +442,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
}
if(dspaceObject != null){
if (dspaceObject != null) {
doc1.addField("id", dspaceObject.getID());
doc1.addField("type", dspaceObject.getType());
storeParents(doc1, dspaceObject);
@@ -470,30 +470,30 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
solrDoc.addField("query", query);
}
if(resultObject != null){
if (resultObject != null) {
//We have a search result
solrDoc.addField("statistics_type", StatisticsType.SEARCH_RESULT.text());
}else{
} else {
solrDoc.addField("statistics_type", StatisticsType.SEARCH.text());
}
//Store the scope
if(scope != null){
if (scope != null) {
solrDoc.addField("scopeId", scope.getID());
solrDoc.addField("scopeType", scope.getType());
}
if(rpp != -1){
if (rpp != -1) {
solrDoc.addField("rpp", rpp);
}
if(sortBy != null){
if (sortBy != null) {
solrDoc.addField("sortBy", sortBy);
if(order != null){
if (order != null) {
solrDoc.addField("sortOrder", order);
}
}
if(page != -1){
if (page != -1) {
solrDoc.addField("page", page);
}
@@ -505,7 +505,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
catch (Exception e)
{
log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}
@@ -518,19 +518,19 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
solrDoc.addField("owningColl", usageWorkflowEvent.getScope().getID());
storeParents(solrDoc, usageWorkflowEvent.getScope());
if(usageWorkflowEvent.getWorkflowStep() != null){
if (usageWorkflowEvent.getWorkflowStep() != null) {
solrDoc.addField("workflowStep", usageWorkflowEvent.getWorkflowStep());
}
if(usageWorkflowEvent.getOldState() != null){
if (usageWorkflowEvent.getOldState() != null) {
solrDoc.addField("previousWorkflowStep", usageWorkflowEvent.getOldState());
}
if(usageWorkflowEvent.getGroupOwners() != null){
if (usageWorkflowEvent.getGroupOwners() != null) {
for (int i = 0; i < usageWorkflowEvent.getGroupOwners().length; i++) {
Group group = usageWorkflowEvent.getGroupOwners()[i];
solrDoc.addField("owner", "g" + group.getID());
}
}
if(usageWorkflowEvent.getEpersonOwners() != null){
if (usageWorkflowEvent.getEpersonOwners() != null) {
for (int i = 0; i < usageWorkflowEvent.getEpersonOwners().length; i++) {
EPerson ePerson = usageWorkflowEvent.getEpersonOwners()[i];
solrDoc.addField("owner", "e" + ePerson.getID());
@@ -540,11 +540,11 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
solrDoc.addField("workflowItemId", usageWorkflowEvent.getWorkflowItem().getID());
EPerson submitter = ((Item) usageWorkflowEvent.getObject()).getSubmitter();
if(submitter != null){
if (submitter != null) {
solrDoc.addField("submitter", submitter.getID());
}
solrDoc.addField("statistics_type", StatisticsType.WORKFLOW.text());
if(usageWorkflowEvent.getActor() != null){
if (usageWorkflowEvent.getActor() != null) {
solrDoc.addField("actor", usageWorkflowEvent.getActor().getID());
}
@@ -553,7 +553,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
catch (Exception e)
{
//Log the exception, no need to send it through, the workflow shouldn't crash because of this !
log.error(e.getMessage(), e);
log.error(e.getMessage(), e);
}
}
@@ -652,7 +652,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
Map<String, String> params = new HashMap<String, String>();
params.put("q", query);
params.put("rows", "10");
if(0 < statisticYearCores.size()){
if (0 < statisticYearCores.size()) {
params.put(ShardParams.SHARDS, StringUtils.join(statisticYearCores.iterator(), ','));
}
MapSolrParams solrParams = new MapSolrParams(params);
@@ -680,10 +680,16 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
/**
* Override to manage pages of documents
*
* @param docs
* a list of Solr documents
* @throws IOException
* A general class of exceptions produced by failed or interrupted I/O operations.
* @throws SolrServerException
* Exception from the Solr server to the solrj Java client.
*/
public void process(List<SolrDocument> docs) throws IOException, SolrServerException {
for(SolrDocument doc : docs){
for (SolrDocument doc : docs) {
process(doc);
}
}
@@ -691,6 +697,11 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
/**
* Override to manage individual documents
* @param doc
* Solr document
* @throws IOException
* A general class of exceptions produced by failed or interrupted I/O operations.
* @throws SolrServerException
* Exception from the Solr server to the solrj Java client.
*/
public void process(SolrDocument doc) throws IOException, SolrServerException {
@@ -702,12 +713,12 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
@Override
public void markRobotsByIP()
{
for(String ip : SpiderDetector.getSpiderIpAddresses()){
for (String ip : SpiderDetector.getSpiderIpAddresses()) {
try {
/* Result Process to alter record to be identified as a bot */
ResultProcessor processor = new ResultProcessor(){
ResultProcessor processor = new ResultProcessor() {
@Override
public void process(SolrDocument doc) throws IOException, SolrServerException {
doc.removeFields("isBot");
@@ -733,11 +744,11 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
@Override
public void markRobotByUserAgent(String agent){
public void markRobotByUserAgent(String agent) {
try {
/* Result Process to alter record to be identified as a bot */
ResultProcessor processor = new ResultProcessor(){
ResultProcessor processor = new ResultProcessor() {
@Override
public void process(SolrDocument doc) throws IOException, SolrServerException {
doc.removeFields("isBot");
@@ -779,7 +790,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
@Override
public void deleteRobotsByIP()
{
for(String ip : SpiderDetector.getSpiderIpAddresses()){
for (String ip : SpiderDetector.getSpiderIpAddresses()) {
deleteIP(ip);
}
}
@@ -796,7 +807,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
final List<SolrDocument> docsToUpdate = new ArrayList<SolrDocument>();
ResultProcessor processor = new ResultProcessor(){
ResultProcessor processor = new ResultProcessor() {
@Override
public void process(List<SolrDocument> docs) throws IOException, SolrServerException {
docsToUpdate.addAll(docs);
@@ -967,10 +978,10 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
if (name != null && name.matches("^[0-9]{4}\\-[0-9]{2}.*"))
{
/*
* if("YEAR".equalsIgnoreCase(type)) return name.substring(0, 4);
* else if("MONTH".equalsIgnoreCase(type)) return name.substring(0,
* 7); else if("DAY".equalsIgnoreCase(type)) return
* name.substring(0, 10); else if("HOUR".equalsIgnoreCase(type))
* if ("YEAR".equalsIgnoreCase(type)) return name.substring(0, 4);
* else if ("MONTH".equalsIgnoreCase(type)) return name.substring(0,
* 7); else if ("DAY".equalsIgnoreCase(type)) return
* name.substring(0, 10); else if ("HOUR".equalsIgnoreCase(type))
* return name.substring(11, 13);
*/
// Get our date
@@ -1081,24 +1092,24 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
// not be influenced
// Choose to filter by the Legacy spider IP list (may get too long to properly filter all IP's
if(configurationService.getBooleanProperty("solr-statistics.query.filter.spiderIp",false))
if (configurationService.getBooleanProperty("solr-statistics.query.filter.spiderIp",false))
{
solrQuery.addFilterQuery(getIgnoreSpiderIPs());
}
// Choose to filter by isBot field, may be overriden in future
// to allow views on stats based on bots.
if(configurationService.getBooleanProperty("solr-statistics.query.filter.isBot",true))
if (configurationService.getBooleanProperty("solr-statistics.query.filter.isBot",true))
{
solrQuery.addFilterQuery("-isBot:true");
}
if(sort != null){
if (sort != null) {
solrQuery.setSortField(sort, (ascending ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc));
}
String[] bundles = configurationService.getArrayProperty("solr-statistics.query.filter.bundles");
if(bundles != null && bundles.length > 0){
if (bundles != null && bundles.length > 0) {
/**
* The code below creates a query that will allow only records which do not have a bundlename
@@ -1110,7 +1121,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
for (int i = 0; i < bundles.length; i++) {
String bundle = bundles[i].trim();
bundleQuery.append("-bundleName:").append(bundle);
if(i != bundles.length - 1){
if (i != bundles.length - 1) {
bundleQuery.append(" AND ");
}
}
@@ -1244,7 +1255,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
log.info("Moving: " + totalRecords + " records into core " + coreName);
List<File> filesToUpload = new ArrayList<File>();
for(int i = 0; i < totalRecords; i+=10000){
for (int i = 0; i < totalRecords; i+=10000) {
String solrRequestUrl = solr.getBaseURL() + "/select";
solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);
@@ -1264,7 +1275,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
//Upload the data in the csv files to our new solr core
ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest("/update/csv");
contentStreamUpdateRequest.setParam("stream.contentType", "text/plain;charset=utf-8");
contentStreamUpdateRequest.setParam("skip", "_version_");
contentStreamUpdateRequest.setParam("skip", "_version_");
contentStreamUpdateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
contentStreamUpdateRequest.addFile(tempCsv, "text/plain;charset=utf-8");
@@ -1284,7 +1295,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
protected HttpSolrServer createCore(HttpSolrServer solr, String coreName) throws IOException, SolrServerException {
String solrDir = configurationService.getProperty("dspace.dir") + File.separator + "solr" +File.separator;
String solrDir = configurationService.getProperty("dspace.dir") + File.separator + "solr" + File.separator;
String baseSolrUrl = solr.getBaseURL().replace("statistics", "");
CoreAdminRequest.Create create = new CoreAdminRequest.Create();
create.setCoreName(coreName);
@@ -1315,7 +1326,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
File tempDirectory = new File(configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator);
tempDirectory.mkdirs();
List<File> tempCsvFiles = new ArrayList<File>();
for(int i = 0; i < totalRecords; i+=10000){
for (int i = 0; i < totalRecords; i+=10000) {
Map<String, String> params = new HashMap<String, String>();
params.put(CommonParams.Q, "*:*");
params.put(CommonParams.FQ, "-bundleName:[* TO *] AND type:" + Constants.BITSTREAM);
@@ -1337,7 +1348,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
//Attempt to find the bitstream id index !
int idIndex = 0;
for (int j = 0; j < header.length; j++) {
if(header[j].equals("id")){
if (header[j].equals("id")) {
idIndex = j;
}
}
@@ -1351,28 +1362,28 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
csvp.writeNext((String[]) ArrayUtils.add(header, "bundleName"));
Map<String, String> bitBundleCache = new HashMap<>();
//Loop over each line (skip the headers though)!
for (int j = 1; j < csvParsed.length; j++){
for (int j = 1; j < csvParsed.length; j++) {
String[] csvLine = csvParsed[j];
//Write the default line !
String bitstreamId = csvLine[idIndex];
//Attempt to retrieve our bundle name from the cache !
String bundleName = bitBundleCache.get(bitstreamId);
if(bundleName == null){
if (bundleName == null) {
//Nothing found retrieve the bitstream
Bitstream bitstream = bitstreamService.findByIdOrLegacyId(context, bitstreamId);
//Attempt to retrieve our bitstream !
if (bitstream != null){
if (bitstream != null) {
List<Bundle> bundles = bitstream.getBundles();
if(bundles != null && 0 < bundles.size()){
if (bundles != null && 0 < bundles.size()) {
Bundle bundle = bundles.get(0);
bundleName = bundle.getName();
}else{
} else {
//No bundle found, we are either a collection or a community logo, check for it !
DSpaceObject parentObject = bitstreamService.getParentObject(context, bitstream);
if(parentObject instanceof Collection){
if (parentObject instanceof Collection) {
bundleName = "LOGO-COLLECTION";
}else
if(parentObject instanceof Community){
} else
if (parentObject instanceof Community) {
bundleName = "LOGO-COMMUNITY";
}
@@ -1383,7 +1394,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
//Check if we don't have a bundlename
//If we don't have one & we do not need to delete the deleted bitstreams ensure that a BITSTREAM_DELETED bundle name is given !
if(bundleName == null && !removeDeletedBitstreams){
if (bundleName == null && !removeDeletedBitstreams) {
bundleName = "BITSTREAM_DELETED";
}
}
@@ -1441,7 +1452,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
long totalRecords = solr.query(query).getResults().getNumFound();
System.out.println("There are " + totalRecords + " usage events in SOLR for download/view.");
for(int i = 0; i < totalRecords; i+=10000){
for (int i = 0; i < totalRecords; i+=10000) {
solrParams.set(CommonParams.START, String.valueOf(i));
QueryResponse queryResponse = solr.query(solrParams);
SolrDocumentList docs = queryResponse.getResults();
@@ -1462,9 +1473,9 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
}
protected void addDocumentsToFile(Context context, SolrDocumentList docs, File exportOutput) throws SQLException, ParseException, IOException {
for(SolrDocument doc : docs) {
for (SolrDocument doc : docs) {
String ip = doc.get("ip").toString();
if(ip.equals("::1")) {
if (ip.equals("::1")) {
ip = "127.0.0.1";
}
@@ -1475,7 +1486,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
//20140527162409835,view_bitstream,1292,2014-05-27T16:24:09,anonymous,127.0.0.1
DSpaceObjectLegacySupportService dsoService = contentServiceFactory.getDSpaceLegacyObjectService(Integer.parseInt(type));
DSpaceObject dso = dsoService.findByIdOrLegacyId(context, id);
if(dso == null) {
if (dso == null) {
log.debug("Document no longer exists in DB. type:" + type + " id:" + id);
continue;
}
@@ -1514,9 +1525,9 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
return result.toString();
}
protected void addAdditionalSolrYearCores(SolrQuery solrQuery){
protected void addAdditionalSolrYearCores(SolrQuery solrQuery) {
//Only add if needed
if(0 < statisticYearCores.size()){
if (0 < statisticYearCores.size()) {
//The shards are a comma separated list of the urls to the cores
solrQuery.add(ShardParams.SHARDS, StringUtils.join(statisticYearCores.iterator(), ","));
}