Java Code Examples for org.alfresco.util.ISO8601DateFormat#format()
The following examples show how to use
org.alfresco.util.ISO8601DateFormat#format() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FavouritesServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private PersonFavourite addFavouriteSite(String userName, NodeRef nodeRef) { PersonFavourite favourite = null; SiteInfo siteInfo = siteService.getSite(nodeRef); if(siteInfo != null) { favourite = getFavouriteSite(userName, siteInfo); if(favourite == null) { Map<String, Serializable> preferences = new HashMap<String, Serializable>(1); String siteFavouritedKey = siteFavouritedKey(siteInfo); preferences.put(siteFavouritedKey, Boolean.TRUE); // ISO8601 string format: PreferenceService works with strings only for dates it seems String siteCreatedAtKey = siteCreatedAtKey(siteInfo); Date createdAt = new Date(); String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(siteCreatedAtKey, createdAtStr); preferenceService.setPreferences(userName, preferences); favourite = new PersonFavourite(userName, siteInfo.getNodeRef(), Type.SITE, siteInfo.getTitle(), createdAt); QName nodeClass = nodeService.getType(nodeRef); OnAddFavouritePolicy policy = onAddFavouriteDelegate.get(nodeRef, nodeClass); policy.onAddFavourite(userName, nodeRef); } } else { // shouldn't happen, getType recognizes it as a site or subtype logger.warn("Unable to get site for " + nodeRef); } return favourite; }
Example 2
Source File: FavouritesServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void updateFavouriteNodes(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> favouriteNodes) { PrefKeys prefKeys = getPrefKeys(type); Map<String, Serializable> preferences = new HashMap<String, Serializable>(1); StringBuilder values = new StringBuilder(); for(PersonFavourite node : favouriteNodes.values()) { NodeRef nodeRef = node.getNodeRef(); values.append(nodeRef.toString()); values.append(","); // ISO8601 string format: PreferenceService works with strings only for dates it seems StringBuilder sb = new StringBuilder(prefKeys.getAlfrescoPrefKey()); sb.append(nodeRef.toString()); sb.append(".createdAt"); String createdAtKey = sb.toString(); Date createdAt = node.getCreatedAt(); if(createdAt != null) { String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(createdAtKey, createdAtStr); } } if(values.length() > 1) { values.delete(values.length() - 1, values.length()); } preferences.put(prefKeys.getSharePrefKey(), values.toString()); preferenceService.setPreferences(userName, preferences); }
Example 3
Source File: AbstractCalendarWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Removes the time zone for a given date if the Calendar Entry is an all day event * * @return ISO 8601 formatted date String if datePattern is null */ protected String removeTimeZoneIfRequired(Date date, Boolean isAllDay, Boolean removeTimezone, String datePattern) { if (removeTimezone) { DateTime dateTime = new DateTime(date, DateTimeZone.UTC); if (null == datePattern) { return dateTime.toString((isAllDay) ? (ALL_DAY_DATETIME_FORMATTER) : (ISODateTimeFormat.dateTime())); } else { // For Legacy Dates and Times. return dateTime.toString(DateTimeFormat.forPattern(datePattern)); } } // This is for all other cases, including the case, when UTC time zone is configured if (!isAllDay && (null == datePattern)) { return ISO8601DateFormat.format(date); } DateFormat simpleDateFormat = new SimpleDateFormat((null != datePattern) ? (datePattern) : (ALL_DAY_DATETIME_PATTERN)); return simpleDateFormat.format(date); }
Example 4
Source File: WebScriptUtil.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public static Map<String, Object> buildDateModel(Date dateTime) { String dateStr = ISO8601DateFormat.format(dateTime); Map<String, Object> model = new HashMap<String, Object>(); model.put(DATE_TIME, dateStr); model.put(FORMAT, ISO8601); return model; }
Example 5
Source File: WorkflowModelBuilderTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public void testBuildWorkflowInstance() throws Exception { WorkflowInstance workflowInstance = makeWorkflowInstance(null); Map<String, Object> model = builder.buildSimple(workflowInstance); assertEquals(workflowInstance.getId(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID)); assertTrue(model.containsKey(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_URL)); assertEquals(workflowInstance.getDefinition().getName(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME)); assertEquals(workflowInstance.getDefinition().getTitle(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE)); assertEquals(workflowInstance.getDefinition().getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION)); assertEquals(workflowInstance.getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_MESSAGE)); assertEquals(workflowInstance.isActive(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE)); String startDate = ISO8601DateFormat.format(workflowInstance.getStartDate()); String endDate = ISO8601DateFormat.format(workflowInstance.getEndDate()); String startDateBuilder = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE)); String endDateBuilder = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_END_DATE)); assertEquals(startDate, startDateBuilder); assertEquals(endDate, endDateBuilder); Map<String, Object> initiator = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_INITIATOR); if (initiator != null) { assertEquals(userName, initiator.get(WorkflowModelBuilder.PERSON_USER_NAME)); assertEquals(firstName, initiator.get(WorkflowModelBuilder.PERSON_FIRST_NAME)); assertEquals(lastName, initiator.get(WorkflowModelBuilder.PERSON_LAST_NAME)); } assertTrue(model.containsKey(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DEFINITION_URL)); }
Example 6
Source File: DefaultTypeConverterTest.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public void testFromString() { assertEquals(Boolean.valueOf(true), DefaultTypeConverter.INSTANCE.convert(Boolean.class, "True")); assertEquals(Boolean.valueOf(false), DefaultTypeConverter.INSTANCE.convert(Boolean.class, "woof")); assertEquals(Character.valueOf('w'), DefaultTypeConverter.INSTANCE.convert(Character.class, "w")); assertEquals(Byte.valueOf("3"), DefaultTypeConverter.INSTANCE.convert(Byte.class, "3")); assertEquals(Short.valueOf("4"), DefaultTypeConverter.INSTANCE.convert(Short.class, "4")); assertEquals(Integer.valueOf("5"), DefaultTypeConverter.INSTANCE.convert(Integer.class, "5")); assertEquals(Long.valueOf("6"), DefaultTypeConverter.INSTANCE.convert(Long.class, "6")); assertEquals(Float.valueOf("7.1"), DefaultTypeConverter.INSTANCE.convert(Float.class, "7.1")); assertEquals(Float.NaN, DefaultTypeConverter.INSTANCE.convert(Float.class, "NaN")); assertEquals(Float.NEGATIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Float.class, "-Infinity")); assertEquals(Float.POSITIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Float.class, "Infinity")); assertEquals(Double.valueOf("123.123"), DefaultTypeConverter.INSTANCE.convert(Double.class, "123.123")); assertEquals(Double.NaN, DefaultTypeConverter.INSTANCE.convert(Double.class, "NaN")); assertEquals(Double.NEGATIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Double.class, "-Infinity")); assertEquals(Double.POSITIVE_INFINITY, DefaultTypeConverter.INSTANCE.convert(Double.class, "Infinity")); assertEquals(new BigInteger("1234567890123456789"), DefaultTypeConverter.INSTANCE.convert(BigInteger.class, "1234567890123456789")); assertEquals(new BigDecimal("12345678901234567890.12345678901234567890"), DefaultTypeConverter.INSTANCE.convert(BigDecimal.class, "12345678901234567890.12345678901234567890")); GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, 3); cal.set(Calendar.DAY_OF_MONTH, 12); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); String isoDate = ISO8601DateFormat.format(cal.getTime()); assertEquals(isoDate, ISO8601DateFormat.format(DefaultTypeConverter.INSTANCE.convert(Date.class, isoDate))); assertEquals(new Duration("P25D"), DefaultTypeConverter.INSTANCE.convert(Duration.class, "P25D")); assertEquals("woof", DefaultTypeConverter.INSTANCE.convert(String.class, "woof")); MLText converted = DefaultTypeConverter.INSTANCE.convert(MLText.class, "woof"); assertEquals("woof", converted.getValue(Locale.getDefault())); assertEquals(Locale.FRANCE, DefaultTypeConverter.INSTANCE.convert(Locale.class, "fr_FR")); assertEquals(Locale.FRANCE, DefaultTypeConverter.INSTANCE.convert(Locale.class, "fr_FR_")); assertEquals(new VersionNumber("1.2.3"), DefaultTypeConverter.INSTANCE.convert(VersionNumber.class, "1.2.3")); assertEquals(new Period("period"), DefaultTypeConverter.INSTANCE.convert(Period.class, "period")); assertEquals(new Period("period|12"), DefaultTypeConverter.INSTANCE.convert(Period.class, "period|12")); Map<String,String> periodMap = new HashMap<String, String>(); periodMap.put("periodType","month"); periodMap.put("expression","1"); assertEquals(new Period(periodMap), DefaultTypeConverter.INSTANCE.convert(Period.class, periodMap)); // Java Class assertEquals(this.getClass().getName(), DefaultTypeConverter.INSTANCE.convert(String.class, this.getClass())); }
Example 7
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
public void testQueryFolderProperties() { Session session = getSession("admin", "admin"); String folderName = getRootFolderName(); Folder root = session.getRootFolder(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); properties.put(PropertyIds.NAME, folderName); // create the folder Folder newFolder = root.createFolder(properties); ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false); assertEquals(1, result.getTotalNumItems()); String uniqueName = getUniqueName(); Map<String, Object> uProperties = new HashMap<String, Object>(); uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); uProperties.put(PropertyIds.NAME, uniqueName); Folder uniqueFolder = newFolder.createFolder(uProperties); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"'", false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND IN_FOLDER('"+ uniqueFolder.getParentId() + "')" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where IN_FOLDER('"+ uniqueFolder.getParentId() + "')" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:createdBy = '"+ uniqueFolder.getCreatedBy()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:objectId = '"+ uniqueFolder.getId()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:lastModifiedBy = '"+ uniqueFolder.getLastModifiedBy()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+ uniqueFolder.getName()+"'" , false); assertEquals(1, result.getTotalNumItems()); String creationDate = ISO8601DateFormat.format(uniqueFolder.getCreationDate().getTime()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:creationDate = '"+ creationDate +"'" , false); assertEquals(1, result.getTotalNumItems()); String modificationDate = ISO8601DateFormat.format(uniqueFolder.getLastModificationDate().getTime()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:lastModificationDate = '"+ modificationDate+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:objectTypeId = '"+ uniqueFolder.getType().getQueryName()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:folder where cmis:name = '"+uniqueName+"' AND cmis:baseTypeId = '"+ uniqueFolder.getBaseType().getQueryName()+"'" , false); assertEquals(1, result.getTotalNumItems()); }
Example 8
Source File: CMISDataCreatorTest.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
public void testQueryDocumentProperties() throws Exception { Session session = getSession("admin", "admin"); String folderName = getRootFolderName(); Folder root = session.getRootFolder(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); properties.put(PropertyIds.NAME, folderName); // create the folder Folder newFolder = root.createFolder(properties); ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false); assertEquals(1, result.getTotalNumItems()); Document uniqueDocument = createUniqueDocument(newFolder); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"'", false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND IN_FOLDER('"+ newFolder.getId() + "')" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where IN_FOLDER('"+ newFolder.getId() + "')" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:createdBy = '"+ uniqueDocument.getCreatedBy()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:objectId = '"+ uniqueDocument.getId()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:lastModifiedBy = '"+ uniqueDocument.getLastModifiedBy()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+ uniqueDocument.getName()+"'" , false); assertEquals(1, result.getTotalNumItems()); String creationDate = ISO8601DateFormat.format(uniqueDocument.getCreationDate().getTime()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:creationDate = '"+ creationDate +"'" , false); assertEquals(1, result.getTotalNumItems()); String modificationDate = ISO8601DateFormat.format(uniqueDocument.getLastModificationDate().getTime()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:lastModificationDate = '"+ modificationDate+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:objectTypeId = '"+ uniqueDocument.getType().getQueryName()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:baseTypeId = '"+ uniqueDocument.getBaseType().getQueryName()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:contentStreamFileName = '"+ uniqueDocument.getContentStreamFileName()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:contentStreamLength = '"+ uniqueDocument.getContentStreamLength()+"'" , false); assertEquals(1, result.getTotalNumItems()); result = session.query("select * from cmis:document where cmis:name = '"+uniqueDocument.getName()+"' AND cmis:contentStreamMimeType = '"+ uniqueDocument.getContentStreamMimeType()+"'" , false); assertEquals(1, result.getTotalNumItems()); }
Example 9
Source File: WorkflowModelBuilderTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public void testBuildWorkflowTask() throws Exception { Date date = new Date(); WorkflowTask task = makeTask(date); Map<String, Object> model = builder.buildSimple(task, null); Object id = model.get(WorkflowModelBuilder.TASK_ID); assertEquals(task.getId(), id); Object url = model.get(WorkflowModelBuilder.TASK_URL); assertEquals("api/task-instances/" + task.getId(), url); assertEquals(task.getName(), model.get(WorkflowModelBuilder.TASK_NAME)); assertEquals(task.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE)); assertEquals(task.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION)); assertEquals(task.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE)); assertNull(model.get(WorkflowModelBuilder.TASK_OUTCOME)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_EDITABLE)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_REASSIGNABLE)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_CLAIMABLE)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_RELEASABLE)); Map<String, Object> owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER); assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME)); assertEquals(firstName, owner.get(WorkflowModelBuilder.PERSON_FIRST_NAME)); assertEquals(lastName, owner.get(WorkflowModelBuilder.PERSON_LAST_NAME)); Map<String, Object> props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES); assertEquals(task.getProperties().size() + 1, props.size()); assertEquals(5, props.get("test_int")); assertEquals(false, props.get("test_boolean")); assertEquals("foo bar", props.get("test_string")); String dateStr = (String) props.get("test_date"); assertEquals(date, ISO8601DateFormat.parse(dateStr)); Map<String, Object> workflowInstance = (Map<String, Object>)model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE); assertNotNull(workflowInstance); WorkflowInstance instance = task.getPath().getInstance(); assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID)); assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE)); String startDateStr = ISO8601DateFormat.format(instance.getStartDate()); String workFlowStartDateStr = (String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE); assertEquals(startDateStr, ISO8601DateFormat.formatToZulu(workFlowStartDateStr)); task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, new ArrayList<NodeRef>(0)); model = builder.buildSimple(task, null); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED)); ArrayList<NodeRef> actors = new ArrayList<NodeRef>(1); actors.add(person); task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, actors); model = builder.buildSimple(task, null); assertEquals(true, model.get(WorkflowModelBuilder.TASK_IS_POOLED)); model = builder.buildSimple(task, Arrays.asList("test_int", "test_string")); //Check task owner still created properly. owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER); assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME)); // Check properties populated correctly props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES); assertEquals(2, props.size()); assertEquals(5, props.get("test_int")); assertEquals("foo bar", props.get("test_string")); }
Example 10
Source File: WorkflowModelBuilderTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public void testBuildWorkflowTaskDetailed() throws Exception { Date date = new Date(); WorkflowTask workflowTask = makeTask(date); Map<String, Object> model = builder.buildDetailed(workflowTask); Object id = model.get(WorkflowModelBuilder.TASK_ID); assertEquals(workflowTask.getId(), id); Object url = model.get(WorkflowModelBuilder.TASK_URL); assertEquals("api/task-instances/" + workflowTask.getId(), url); assertEquals(workflowTask.getName(), model.get(WorkflowModelBuilder.TASK_NAME)); assertEquals(workflowTask.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE)); assertEquals(workflowTask.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION)); assertEquals(workflowTask.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED)); Map<String, Object> owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER); assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME)); assertEquals(firstName, owner.get(WorkflowModelBuilder.PERSON_FIRST_NAME)); assertEquals(lastName, owner.get(WorkflowModelBuilder.PERSON_LAST_NAME)); Map<String, Object> props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES); assertEquals(workflowTask.getProperties().size() + 1, props.size()); Map<String, Object> workflowInstance = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE); WorkflowInstance instance = workflowTask.getPath().getInstance(); assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID)); assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE)); String startDateStr = ISO8601DateFormat.format(instance.getStartDate()); String startDateBuilderStr = ISO8601DateFormat.formatToZulu((String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE)); assertEquals(startDateStr, startDateBuilderStr); WorkflowDefinition workflowDef = instance.getDefinition(); assertEquals(workflowDef.getName(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME)); assertEquals(workflowDef.getTitle(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE)); assertEquals(workflowDef.getDescription(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION)); Map<String, Object> actualDefinition = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_DEFINITION); WorkflowTaskDefinition taskDef = workflowTask.getDefinition(); assertEquals(taskDef.getId(), actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_ID)); Map<String, Object> actualType = (Map<String, Object>) actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_TYPE); TypeDefinition taskType = taskDef.getMetadata(); assertEquals(taskType.getName(), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_NAME)); assertEquals(taskType.getTitle(dictionaryService), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_TITLE)); assertEquals(taskType.getDescription(dictionaryService), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_DESCRIPTION)); Map<String, Object> actualNode = (Map<String, Object>) actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_NODE); WorkflowNode taskNode = taskDef.getNode(); assertEquals(taskNode.getName(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_NAME)); assertEquals(taskNode.getTitle(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_TITLE)); assertEquals(taskNode.getDescription(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_DESCRIPTION)); assertEquals(taskNode.isTaskNode(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_IS_TASK_NODE)); List<Map<String, Object>> transitions = (List<Map<String, Object>>) actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITIONS); WorkflowTransition[] taskTransitions = taskNode.getTransitions(); int i = 0; for (Map<String, Object> transition : transitions) { WorkflowTransition workflowTransition = taskTransitions[i]; assertEquals(workflowTransition.getId(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_ID)); assertEquals(workflowTransition.getTitle(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_TITLE)); assertEquals(workflowTransition.getDescription(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_DESCRIPTION)); assertEquals(workflowTransition.isDefault(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_IS_DEFAULT)); assertEquals(false, transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_IS_HIDDEN)); i++; } }
Example 11
Source File: WorkflowModelBuilderTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public void testBuildWorkflowInstanceDetailed() throws Exception { WorkflowTaskDefinition workflowTaskDefinition = makeTaskDefinition(); QName taskTypeName = WorkflowModel.TYPE_WORKFLOW_TASK; when(workflowTaskDefinition.getMetadata().getName()).thenReturn(taskTypeName); when(workflowTaskDefinition.getMetadata().getTitle(dictionaryService)).thenReturn("The Type Title"); when(workflowTaskDefinition.getMetadata().getDescription(dictionaryService)).thenReturn("The Type Description"); WorkflowInstance workflowInstance = makeWorkflowInstance(workflowTaskDefinition); Map<String, Object> model = builder.buildDetailed(workflowInstance, true); assertEquals(workflowInstance.getId(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID)); assertEquals(workflowInstance.getDefinition().getName(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME)); assertEquals(workflowInstance.getDefinition().getTitle(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE)); assertEquals(workflowInstance.getDefinition().getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION)); assertEquals(workflowInstance.isActive(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE)); String startDateStr = ISO8601DateFormat.format(workflowInstance.getStartDate()); String endDateStr = ISO8601DateFormat.format(workflowInstance.getEndDate()); String startDateBuilderStr = ISO8601DateFormat.formatToZulu((String)model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE)) ; String endDateBuilderStr = ISO8601DateFormat.formatToZulu((String)model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_END_DATE)); assertEquals( startDateStr,startDateBuilderStr); assertEquals(endDateStr, endDateBuilderStr); Map<String, Object> initiator = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_INITIATOR); if (initiator != null) { assertEquals(userName, initiator.get(WorkflowModelBuilder.PERSON_USER_NAME)); assertEquals(firstName, initiator.get(WorkflowModelBuilder.PERSON_FIRST_NAME)); assertEquals(lastName, initiator.get(WorkflowModelBuilder.PERSON_LAST_NAME)); } assertEquals(workflowInstance.getContext().toString(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_CONTEXT)); assertEquals(workflowInstance.getWorkflowPackage().toString(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_PACKAGE)); Map<String, Object> taskInstanceModel = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DEFINITION); assertEquals(workflowInstance.getDefinition().getVersion(), taskInstanceModel.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_VERSION)); assertEquals(workflowInstance.getDefinition().getStartTaskDefinition().getMetadata().getName(), taskInstanceModel.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_START_TASK_DEFINITION_TYPE)); }
Example 12
Source File: AuditAppTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private void testAuditEntriesWhereDate(AuditApps auditAppsProxy, AuditApp auditApp) throws Exception { // paging Paging paging = getPaging(0, 10); Date dateBefore = new Date(); String dateBeforeWhere = ISO8601DateFormat.format(dateBefore); createUser("usern-" + RUNID, "userNPassword", networkOne); login("usern-" + RUNID, "userNPassword"); Date dateAfter = new Date(); String dateAfterWhere = ISO8601DateFormat.format(dateAfter); Map<String, String> otherParams = new HashMap<>(); otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'" + dateBeforeWhere + "\'" + ", " + "\'" + dateAfterWhere + "\'" + "))"); ListResponse<AuditEntry> auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, otherParams), HttpServletResponse.SC_OK); assertNotNull(auditEntries); assertTrue(auditEntries.getList().size() > 0); for (AuditEntry ae : auditEntries.getList()) { validateAuditEntryFields(ae, auditApp); } // // note: sanity test parsing of a few ISO8601 formats (non-exhaustive) - eg. +01:00, +0000, Z // otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'2016-06-02T12:13:51.593+01:00\'" + ", " + "\'2017-06-04T10:05:16.536+01:00\'" + "))"); auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, otherParams), HttpServletResponse.SC_OK); otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'2016-06-02T11:13:51.593+0000\'" + ", " + "\'2017-06-04T09:05:16.536+0000\'" + "))"); auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, otherParams), HttpServletResponse.SC_OK); otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'2016-06-02T11:13:51.593Z\'" + ", " + "\'2017-06-04T09:05:16.536Z\'" + "))"); auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, otherParams), HttpServletResponse.SC_OK); // Negative tests otherParams = new HashMap<>(); otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'2017-06-04T10:05:16.536+01:00\'" + ", " + "\'2016-06-02T12:13:51.593+01:00\'" + "))"); auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, otherParams), HttpServletResponse.SC_BAD_REQUEST); }
Example 13
Source File: AuditAppTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private void testDeleteAuditEntries(AuditApps auditAppsProxy, AuditApp auditApp) throws Exception { int skipCount = 0; int maxItems = 4; Paging paging = getPaging(skipCount, maxItems); Map<String, String> otherParams = new HashMap<>(); ListResponse<AuditEntry> resp = auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, otherParams), HttpServletResponse.SC_OK); String dateBefore = ISO8601DateFormat.format(resp.getList().get(0).getCreatedAt()); String dateAfter = ISO8601DateFormat.format(resp.getList().get(2).getCreatedAt()); Long secondDeleteEntryId = resp.getList().get(1).getId(); Long lastDeleteEntryId = resp.getList().get(2).getId(); // Negative tests // 400 - switched dates and consecutive switched IDs otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'" + dateAfter + "\'" + ", " + "\'" + dateBefore + "\'" + "))"); auditAppsProxy.deleteAuditEntries(auditApp.getId(), otherParams, HttpServletResponse.SC_BAD_REQUEST); otherParams.put("where", "(" + org.alfresco.rest.api.Audit.ID + " between (" + "\'" + lastDeleteEntryId + "\'" + ", " + "\'" + secondDeleteEntryId + "\'" + "))"); auditAppsProxy.deleteAuditEntries(auditApp.getId(), otherParams, HttpServletResponse.SC_BAD_REQUEST); // 401 // put correct dates back otherParams.put("where", "(" + org.alfresco.rest.api.Audit.CREATED_AT + " between (" + "\'" + dateBefore + "\'" + ", " + "\'" + dateAfter + "\'" + "))"); setRequestContext(networkOne.getId(), networkAdmin, "wrongPassword"); auditAppsProxy.deleteAuditEntries(auditApp.getId(), otherParams, HttpServletResponse.SC_UNAUTHORIZED); // 403 setRequestContext(networkOne.getId(), user1, null); auditAppsProxy.deleteAuditEntries(auditApp.getId(), otherParams, HttpServletResponse.SC_FORBIDDEN); // 404 setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); auditAppsProxy.deleteAuditEntries("invalidAppId", otherParams, HttpServletResponse.SC_NOT_FOUND); // 501 setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); AuthenticationUtil.setFullyAuthenticatedUser(networkAdmin); disableSystemAudit(); auditAppsProxy.deleteAuditEntries(auditApp.getId(), otherParams, HttpServletResponse.SC_NOT_IMPLEMENTED);; enableSystemAudit(); // Positive tests // 200 auditAppsProxy.deleteAuditEntries(auditApp.getId(), otherParams, HttpServletResponse.SC_NO_CONTENT); // check that the entries were deleted. // firstEntry should have id > than lastDeleteEntryId resp = auditAppsProxy.getAuditAppEntries(auditApp.getId(), createParams(paging, new HashMap<>()), HttpServletResponse.SC_OK); assertTrue("Entries were not deleted", resp.getList().get(0).getId() > lastDeleteEntryId); }