RM-4162: fixed formatting

This commit is contained in:
Silviu Dinuta
2016-09-29 22:44:37 +03:00
parent 31c6b1e228
commit 39a8273063
2 changed files with 537 additions and 529 deletions

View File

@@ -96,6 +96,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
private static final String MESSAGE_PARTIAL_TEMPLATE = "Processed first {0} records."; private static final String MESSAGE_PARTIAL_TEMPLATE = "Processed first {0} records.";
private static final String MESSAGE_NO_RECORDS_TO_PROCESS = "There where no records to be processed."; private static final String MESSAGE_NO_RECORDS_TO_PROCESS = "There where no records to be processed.";
/** services */ /** services */
private PatchDAO patchDAO; private PatchDAO patchDAO;
private NodeDAO nodeDAO; private NodeDAO nodeDAO;
@@ -161,7 +162,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
// get the max node id and the extended security aspect // get the max node id and the extended security aspect
Long maxNodeId = patchDAO.getMaxAdmNodeID(); Long maxNodeId = patchDAO.getMaxAdmNodeID();
final Pair<Long, QName> recordAspectPair = qnameDAO.getQName(ASPECT_EXTENDED_SECURITY); final Pair<Long, QName> recordAspectPair = qnameDAO.getQName(ASPECT_EXTENDED_SECURITY);
if (recordAspectPair == null) if(recordAspectPair == null)
{ {
model.put(MODEL_STATUS, SUCCESS_STATUS); model.put(MODEL_STATUS, SUCCESS_STATUS);
model.put(MODEL_MESSAGE, MESSAGE_NO_RECORDS_TO_PROCESS); model.put(MODEL_MESSAGE, MESSAGE_NO_RECORDS_TO_PROCESS);
@@ -184,7 +185,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
{ {
processedNodes = processChildrenNodes(parentNodeRef, batchSize.intValue(), recordAspectPair, processedNodes = processChildrenNodes(parentNodeRef, batchSize.intValue(), recordAspectPair,
totalNumberOfRecordsToProcess.intValue(), out, attach); totalNumberOfRecordsToProcess.intValue(), out, attach);
} }
else else
{ {
processedNodes = processNodes(batchSize, maxNodeId, recordAspectPair, totalNumberOfRecordsToProcess, processedNodes = processNodes(batchSize, maxNodeId, recordAspectPair, totalNumberOfRecordsToProcess,
@@ -262,8 +263,10 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
try try
{ {
String mimetype = getContainer().getFormatRegistry().getMimeType(req.getAgent(), format); String mimetype = getContainer().getFormatRegistry().getMimeType(req.getAgent(), format);
if (mimetype == null) { throw new WebScriptException( if (mimetype == null)
"Web Script format '" + format + "' is not registered"); } {
throw new WebScriptException("Web Script format '" + format + "' is not registered");
}
// construct model for script / template // construct model for script / template
Status status = new Status(); Status status = new Status();
@@ -362,7 +365,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
protected Long getMaxToProccessParameter(WebScriptRequest req, final Long batchSize) protected Long getMaxToProccessParameter(WebScriptRequest req, final Long batchSize)
{ {
String totalToBeProcessedRecordsStr = req.getParameter(TOTAL_NUMBER_TO_PROCESS); String totalToBeProcessedRecordsStr = req.getParameter(TOTAL_NUMBER_TO_PROCESS);
// default total number of records to be processed to batch size value //default total number of records to be processed to batch size value
Long totalNumberOfRecordsToProcess = batchSize; Long totalNumberOfRecordsToProcess = batchSize;
if (StringUtils.isNotBlank(totalToBeProcessedRecordsStr)) if (StringUtils.isNotBlank(totalToBeProcessedRecordsStr))
{ {
@@ -370,9 +373,9 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
{ {
totalNumberOfRecordsToProcess = Long.parseLong(totalToBeProcessedRecordsStr); totalNumberOfRecordsToProcess = Long.parseLong(totalToBeProcessedRecordsStr);
} }
catch (NumberFormatException ex) catch(NumberFormatException ex)
{ {
// do nothing here, the value will remain 0L in this case //do nothing here, the value will remain 0L in this case
} }
} }
return totalNumberOfRecordsToProcess; return totalNumberOfRecordsToProcess;
@@ -450,9 +453,9 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
final List<NodeRef> processedNodes = new ArrayList<NodeRef>(); final List<NodeRef> processedNodes = new ArrayList<NodeRef>();
logger.info(MESSAGE_PROCESSING_BEGIN); logger.info(MESSAGE_PROCESSING_BEGIN);
// by batch size // by batch size
for (Long i = 0L; i < maxNodeId; i += batchSize) for (Long i = 0L; i < maxNodeId; i+=batchSize)
{ {
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess) if(maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
{ {
break; break;
} }
@@ -469,7 +472,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
// process each one // process each one
for (Long nodeId : nodeIds) for (Long nodeId : nodeIds)
{ {
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess) if(maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
{ {
break; break;
} }
@@ -491,7 +494,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
return null; return null;
} }
}, false, // read only }, false, // read only
true); // requires new true); // requires new
} }
logger.info(MESSAGE_PROCESSING_END); logger.info(MESSAGE_PROCESSING_END);
return processedNodes; return processedNodes;
@@ -557,12 +560,12 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
* *
* @param nodeRef * @param nodeRef
*/ */
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked"})
protected void processNode(NodeRef nodeRef) protected void processNode(NodeRef nodeRef)
{ {
// get the reader/writer data // get the reader/writer data
Map<String, Integer> readers = (Map<String, Integer>) nodeService.getProperty(nodeRef, PROP_READERS); Map<String, Integer> readers = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_READERS);
Map<String, Integer> writers = (Map<String, Integer>) nodeService.getProperty(nodeRef, PROP_WRITERS); Map<String, Integer> writers = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_WRITERS);
// remove extended security aspect // remove extended security aspect
nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY); nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
@@ -576,7 +579,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
{ {
Set<String> readersKeySet = null; Set<String> readersKeySet = null;
if (readers != null) if (readers != null)
{ {
readersKeySet = readers.keySet(); readersKeySet = readers.keySet();
} }
Set<String> writersKeySet = null; Set<String> writersKeySet = null;

View File

@@ -172,7 +172,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
} }
/** /**
* Given that there are no nodes with the extended security aspect When the action is executed Nothing happens * Given that there are no nodes with the extended security aspect
* When the action is executed Nothing happens
* *
* @throws Exception * @throws Exception
*/ */
@@ -205,8 +206,11 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
} }
/** /**
* Given that there are records with the extended security aspect When the action is executed Then the aspect is * Given that there are records with the extended security aspect
* removed And the dynamic authorities permissions are cleared And extended security is set via the updated API * When the action is executed
* Then the aspect is removed
* And the dynamic authorities permissions are cleared
* And extended security is set via the updated API
* *
* @throws Exception * @throws Exception
*/ */
@@ -227,7 +231,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS)) when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
}); });
// Set up parameters. // Set up parameters.
@@ -251,8 +254,9 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
} }
/** /**
* Given that there are non-records with the extended security aspect When the web script is executed Then the * Given that there are non-records with the extended security aspect
* aspect is removed And the dynamic authorities permissions are cleared * When the web script is executed
* Then the aspect is removed And the dynamic authorities permissions are cleared
* *
* @throws Exception * @throws Exception
*/ */
@@ -263,7 +267,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList()); List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids) when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
.thenReturn(Collections.emptyList()); .thenReturn(Collections.emptyList());
ids.stream().forEach((i) -> { ids.stream().forEach((i) -> {
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
@@ -273,7 +277,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS)) when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
}); });
// Set up parameters. // Set up parameters.
@@ -285,6 +288,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}"; String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString)); assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS)); verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS)); verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY)); verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
@@ -315,8 +319,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
{ {
try try
{ {
// Set up parameters. // Set up parameters.
Map<String, String> parameters = ImmutableMap.of("batchsize", "dd"); Map<String, String> parameters = ImmutableMap.of("batchsize", "dd");
executeJSONWebScript(parameters); executeJSONWebScript(parameters);
fail("Expected exception as parameter batchsize is invalid."); fail("Expected exception as parameter batchsize is invalid.");
} }
@@ -332,8 +336,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
{ {
try try
{ {
// Set up parameters. // Set up parameters.
Map<String, String> parameters = ImmutableMap.of("batchsize", "0"); Map<String, String> parameters = ImmutableMap.of("batchsize", "0");
executeJSONWebScript(parameters); executeJSONWebScript(parameters);
fail("Expected exception as parameter batchsize is not a number greater than 0."); fail("Expected exception as parameter batchsize is not a number greater than 0.");
} }
@@ -361,10 +365,10 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
@Test @Test
public void processAllRecordsWhenMaxProcessedRecordsIsZero() throws Exception public void processAllRecordsWhenMaxProcessedRecordsIsZero() throws Exception
{ {
List<Long> ids = Stream.of(1l, 2l, 3l, 4l).collect(Collectors.toList()); List<Long> ids = Stream.of(1l, 2l, 3l,4l).collect(Collectors.toList());
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids) when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
.thenReturn(Collections.emptyList()); .thenReturn(Collections.emptyList());
ids.stream().forEach((i) -> { ids.stream().forEach((i) -> {
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
@@ -374,7 +378,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS)) when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
}); });
// Set up parameters. // Set up parameters.
@@ -393,7 +396,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l).collect(Collectors.toList()); List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l).collect(Collectors.toList());
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids) when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
.thenReturn(Collections.emptyList()); .thenReturn(Collections.emptyList());
ids.stream().forEach((i) -> { ids.stream().forEach((i) -> {
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
@@ -403,7 +406,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS)) when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
.thenReturn((Serializable) Collections.emptyMap()); .thenReturn((Serializable) Collections.emptyMap());
}); });
// Set up parameters. // Set up parameters.
@@ -518,9 +520,10 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
} }
/** /**
* Given I have records that require migration And I am interested in knowning which records are migrated When I run * Given I have records that require migration
* the migration tool Then I will be returned a CSV file containing the name and node reference of the record * And I am interested in knowning which records are migrated
* migrated * When I run the migration tool
* Then I will be returned a CSV file containing the name and node reference of the record migrated
* *
* @throws Exception * @throws Exception
*/ */
@@ -558,8 +561,10 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
} }
/** /**
* Given that I have record that require migration And I'm not interested in knowing which records were migrated * Given that I have record that require migration
* When I run the migration tool And I will not be returned a CSV file of details. * And I'm not interested in knowing which records were migrated
* When I run the migration tool
* Then I will not be returned a CSV file of details.
* *
* @throws Exception * @throws Exception
*/ */