org.alfresco.util.ISO8601DateFormat Java Examples
The following examples show how to use
org.alfresco.util.ISO8601DateFormat.
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: AuditEntry.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static AuditEntry parseAuditEntry(JSONObject jsonObject) { Long id = (Long) jsonObject.get("id"); String auditApplicationId = (String) jsonObject.get("auditApplicationId"); Map<String, Serializable> values = (Map<String, Serializable>) jsonObject.get("values"); org.alfresco.rest.api.model.UserInfo createdByUser = null; JSONObject createdByUserJson = (JSONObject) jsonObject.get("createdByUser"); if (createdByUserJson != null) { String userId = (String) createdByUserJson.get("id"); String displayName = (String) createdByUserJson.get("displayName"); createdByUser = new org.alfresco.rest.api.model.UserInfo(userId,displayName,displayName); } Date createdAt = ISO8601DateFormat.parse((String) jsonObject.get("createdAt")); AuditEntry auditEntry = new AuditEntry(id, auditApplicationId, createdByUser, createdAt, values); return auditEntry; }
Example #2
Source File: DateQuarterRouter.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
public Boolean routeNode(int numShards, int shardInstance, Node node) { if(numShards <= 1) { return true; } String ISO8601Date = node.getShardPropertyValue(); Date date = ISO8601DateFormat.parse(ISO8601Date); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); // Avoid using Math.ceil with Integer int countMonths = ((year * 12) + (month+1)); int grouping = 3; int ceilGroupInstance = (countMonths + grouping - 1) / grouping; return ceilGroupInstance % numShards == shardInstance; }
Example #3
Source File: WebScriptUtil.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public static Date getDate(JSONObject json) throws ParseException { if(json == null) { return null; } String dateTime = json.optString(DATE_TIME); if(dateTime == null) { return null; } String format = json.optString(FORMAT); if(format!= null && ISO8601.equals(format) == false) { SimpleDateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.parse(dateTime); } return ISO8601DateFormat.parse(dateTime); }
Example #4
Source File: RunningActionModelBuilder.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Build a model for a single action */ private Map<String,Object> buildModel(ExecutionSummary summary) { if(summary == null) { return null; } // Get the details, if we can ExecutionDetails details = actionTrackingService.getExecutionDetails(summary); // Only record if still running - may have finished // between getting the list and now if(details != null) { Map<String, Object> ram = new HashMap<String,Object>(); ram.put(ACTION_ID, summary.getActionId()); ram.put(ACTION_TYPE, summary.getActionType()); ram.put(ACTION_INSTANCE, summary.getExecutionInstance()); ram.put(ACTION_KEY, AbstractActionWebscript.getRunningId(summary)); ram.put(ACTION_NODE_REF, details.getPersistedActionRef()); ram.put(ACTION_RUNNING_ON, details.getRunningOn()); ram.put(ACTION_CANCEL_REQUESTED, details.isCancelRequested()); if(details.getStartedAt() != null) { ram.put(ACTION_STARTED_AT, ISO8601DateFormat.format(details.getStartedAt())); } else { ram.put(ACTION_STARTED_AT, null); } return ram; } return null; }
Example #5
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 #6
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 #7
Source File: AbstractCalendarListingWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private void updateRepeatingStartEnd(Date newStart, long duration, Map<String, Object> result) { Date newEnd = new Date(newStart.getTime() + duration); result.put(RESULT_START, ISO8601DateFormat.format(newStart)); result.put(RESULT_END, ISO8601DateFormat.format(newEnd)); String legacyDateFormat = "yyyy-MM-dd"; SimpleDateFormat ldf = new SimpleDateFormat(legacyDateFormat); String legacyTimeFormat ="HH:mm"; SimpleDateFormat ltf = new SimpleDateFormat(legacyTimeFormat); result.put("legacyDateFrom", ldf.format(newStart)); result.put("legacyTimeFrom", ltf.format(newStart)); result.put("legacyDateTo", ldf.format(newEnd)); result.put("legacyTimeTo", ltf.format(newEnd)); }
Example #8
Source File: AbstractSubscriptionServiceWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") protected JSONObject getUserDetails(String username) { NodeRef node = personService.getPerson(username); JSONObject result = new JSONObject(); result.put("userName", username); result.put("firstName", nodeService.getProperty(node, ContentModel.PROP_FIRSTNAME)); result.put("lastName", nodeService.getProperty(node, ContentModel.PROP_LASTNAME)); result.put("jobtitle", nodeService.getProperty(node, ContentModel.PROP_JOBTITLE)); result.put("organization", nodeService.getProperty(node, ContentModel.PROP_ORGANIZATION)); String status = (String) nodeService.getProperty(node, ContentModel.PROP_USER_STATUS); if (status != null) { result.put("userStatus", status); } Date statusTime = (Date) nodeService.getProperty(node, ContentModel.PROP_USER_STATUS_TIME); if (statusTime != null) { JSONObject statusTimeJson = new JSONObject(); statusTimeJson.put("iso8601", ISO8601DateFormat.format(statusTime)); result.put("userStatusTime", statusTimeJson); } // Get the avatar for the user id if one is available List<AssociationRef> assocRefs = this.nodeService.getTargetAssocs(node, ContentModel.ASSOC_AVATAR); if (!assocRefs.isEmpty()) { NodeRef avatarNodeRef = assocRefs.get(0).getTargetRef(); result.put("avatar", avatarNodeRef.toString()); } else { result.put("avatar", "avatar"); // This indicates to just use a placeholder } return result; }
Example #9
Source File: DateMonthRouter.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Boolean routeNode(int numShards, int shardInstance, Node node) { if(numShards <= 1) { return true; } String ISO8601Date = node.getShardPropertyValue(); if(ISO8601Date == null) { return dbidRouter.routeNode(numShards, shardInstance, node); } try { Date date = ISO8601DateFormat.parse(ISO8601Date); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); int month = cal.get(Calendar.MONTH); int year = cal.get(Calendar.YEAR); return ((((year * 12) + month) / grouping) % numShards) == shardInstance; } catch (Exception exception) { return dbidRouter.routeNode(numShards, shardInstance, node); } }
Example #10
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 #11
Source File: DatePropertyValueComparator.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private Date getDate(Serializable value) { if(value instanceof Date) { return (Date) value; } else if(value instanceof String) { return ISO8601DateFormat.parse((String) value); } throw new AlfrescoRuntimeException("Parameter 'compareValue' must be of type java.util.Date!"); }
Example #12
Source File: FavouritesServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void extractFavouriteSite(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> sortedFavouriteNodes, Map<String, Serializable> preferences, String key) { // preference value indicates whether the site has been favourited Serializable pref = preferences.get(key); Boolean isFavourite = (Boolean)pref; if(isFavourite) { PrefKeys sitePrefKeys = getPrefKeys(Type.SITE); int length = sitePrefKeys.getSharePrefKey().length(); String siteId = key.substring(length); try { SiteInfo siteInfo = siteService.getSite(siteId); if(siteInfo != null) { StringBuilder builder = new StringBuilder(sitePrefKeys.getAlfrescoPrefKey()); builder.append(siteId); builder.append(".createdAt"); String createdAtPrefKey = builder.toString(); String createdAtStr = (String)preferences.get(createdAtPrefKey); Date createdAt = null; if(createdAtStr != null) { createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr): null); } PersonFavourite personFavourite = new PersonFavourite(userName, siteInfo.getNodeRef(), Type.SITE, siteId, createdAt); sortedFavouriteNodes.put(personFavourite.getKey(), personFavourite); } } catch(AccessDeniedException ex) { // the user no longer has access to this site, skip over the favourite // TODO remove the favourite preference return; } } }
Example #13
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 #14
Source File: FavouritesServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private PersonFavourite getFavouriteSite(String userName, SiteInfo siteInfo) { PersonFavourite favourite = null; String siteFavouritedKey = siteFavouritedKey(siteInfo); String siteCreatedAtKey = siteCreatedAtKey(siteInfo); Boolean isFavourited = false; Serializable s = preferenceService.getPreference(userName, siteFavouritedKey); if(s != null) { if(s instanceof String) { isFavourited = Boolean.valueOf((String)s); } else if(s instanceof Boolean) { isFavourited = (Boolean)s; } else { throw new AlfrescoRuntimeException("Unexpected favourites preference value"); } } if(isFavourited) { String createdAtStr = (String)preferenceService.getPreference(userName, siteCreatedAtKey); Date createdAt = (createdAtStr == null ? null : ISO8601DateFormat.parse(createdAtStr)); favourite = new PersonFavourite(userName, siteInfo.getNodeRef(), Type.SITE, siteInfo.getTitle(), createdAt); } return favourite; }
Example #15
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 #16
Source File: EnterpriseWorkflowTestApi.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Start a review pooled process through the public REST-API. */ @SuppressWarnings("unchecked") protected ProcessInfo startReviewPooledProcess(final RequestContext requestContext) throws PublicApiException { org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine .getRepositoryService() .createProcessDefinitionQuery() .processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiReviewPooled") .singleResult(); ProcessesClient processesClient = publicApiClient.processesClient(); final JSONObject createProcessObject = new JSONObject(); createProcessObject.put("processDefinitionId", processDefinition.getId()); final JSONObject variablesObject = new JSONObject(); variablesObject.put("bpm_priority", 1); variablesObject.put("bpm_workflowDueDate", ISO8601DateFormat.format(new Date())); variablesObject.put("wf_notifyMe", Boolean.FALSE); TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() { @Override public Void doWork() throws Exception { List<MemberOfSite> memberships = getTestFixture().getNetwork(requestContext.getNetworkId()).getSiteMemberships(requestContext.getRunAsUser()); assertTrue(memberships.size() > 0); MemberOfSite memberOfSite = memberships.get(0); String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name(); variablesObject.put("bpm_groupAssignee", group); return null; } }, requestContext.getRunAsUser(), requestContext.getNetworkId()); createProcessObject.put("variables", variablesObject); return processesClient.createProcess(createProcessObject.toJSONString()); }
Example #17
Source File: MapBasedQueryWalker.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
protected void processVariable(String propertyName, String propertyValue, int type) { String localPropertyName = propertyName.replaceFirst("variables/", ""); Object actualValue = null; DataTypeDefinition dataTypeDefinition = null; // variable scope global is default String scopeDef = "global"; // look for variable scope if (localPropertyName.contains("local/")) { scopeDef = "local"; localPropertyName = localPropertyName.replaceFirst("local/", ""); } if (localPropertyName.contains("global/")) { localPropertyName = localPropertyName.replaceFirst("global/", ""); } // look for variable type definition if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" ")) { int indexOfSpace = propertyValue.indexOf(' '); if ((propertyValue.contains("_") && indexOfSpace > propertyValue.indexOf("_")) || (propertyValue.contains(":") && indexOfSpace > propertyValue.indexOf(":"))) { String typeDef = propertyValue.substring(0, indexOfSpace); try { QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService); dataTypeDefinition = dictionaryService.getDataType(dataType); propertyValue = propertyValue.substring(indexOfSpace + 1); } catch (Exception e) { throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue); } } } if (dataTypeDefinition != null && "java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName())) { // fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf) actualValue = ISO8601DateFormat.parse(propertyValue); } else if (dataTypeDefinition != null) { actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, propertyValue); } else { actualValue = propertyValue; } variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue, scopeDef)); }
Example #18
Source File: ProcessWorkflowApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void testCreateProcessInstanceFromOtherNetwork() throws Exception { final RequestContext requestContext = initApiClientWithTestUser(); org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine .getRepositoryService() .createProcessDefinitionQuery() .processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc") .singleResult(); TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId()); String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId(); RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin); publicApiClient.setRequestContext(otherContext); ProcessesClient processesClient = publicApiClient.processesClient(); JSONObject createProcessObject = new JSONObject(); createProcessObject.put("processDefinitionId", processDefinition.getId()); final JSONObject variablesObject = new JSONObject(); variablesObject.put("bpm_dueDate", ISO8601DateFormat.format(new Date())); variablesObject.put("bpm_priority", 1); variablesObject.put("bpm_description", "test description"); TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() { @Override public Void doWork() throws Exception { variablesObject.put("bpm_assignee", requestContext.getRunAsUser()); return null; } }, requestContext.getRunAsUser(), requestContext.getNetworkId()); createProcessObject.put("variables", variablesObject); try { processesClient.createProcess(createProcessObject.toJSONString()); } catch (PublicApiException e) { assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode()); } }
Example #19
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 #20
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 #21
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 #22
Source File: AbstractWorkflowRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public void testWorkflowInstanceGet() throws Exception { //Start workflow as USER1 and assign task to USER2. personManager.setUser(USER1); WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName()); Map<QName, Serializable> params = new HashMap<QName, Serializable>(); params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2)); Date dueDate = new Date(); params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate); params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1); params.put(WorkflowModel.ASSOC_PACKAGE, packageRef); params.put(WorkflowModel.PROP_CONTEXT, packageRef); WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params); String WorkflowId = adhocPath.getInstance().getId(); workflows.add(WorkflowId); // End start task. WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0); startTask = workflowService.endTask(startTask.getId(), null); WorkflowInstance adhocInstance = startTask.getPath().getInstance(); Response response = sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId() + "?includeTasks=true"), 200); assertEquals(Status.STATUS_OK, response.getStatus()); String jsonStr = response.getContentAsString(); JSONObject json = new JSONObject(jsonStr); JSONObject result = json.getJSONObject("data"); assertNotNull(result); assertEquals(adhocInstance.getId(), result.getString("id")); assertTrue(result.opt("message").equals(JSONObject.NULL)); assertEquals(adhocInstance.getDefinition().getName(), result.getString("name")); assertEquals(adhocInstance.getDefinition().getTitle(), result.getString("title")); assertEquals(adhocInstance.getDefinition().getDescription(), result.getString("description")); assertEquals(adhocInstance.isActive(), result.getBoolean("isActive")); assertEquals(org.springframework.extensions.surf.util.ISO8601DateFormat.format(adhocInstance.getStartDate()), result.getString("startDate")); assertNotNull(result.get("dueDate")); assertNotNull(result.get("endDate")); assertEquals(1, result.getInt("priority")); JSONObject initiator = result.getJSONObject("initiator"); assertEquals(USER1, initiator.getString("userName")); assertEquals(personManager.getFirstName(USER1), initiator.getString("firstName")); assertEquals(personManager.getLastName(USER1), initiator.getString("lastName")); assertEquals(adhocInstance.getContext().toString(), result.getString("context")); assertEquals(adhocInstance.getWorkflowPackage().toString(), result.getString("package")); assertNotNull(result.getString("startTaskInstanceId")); JSONObject jsonDefinition = result.getJSONObject("definition"); WorkflowDefinition adhocDefinition = adhocInstance.getDefinition(); assertNotNull(jsonDefinition); assertEquals(adhocDefinition.getId(), jsonDefinition.getString("id")); assertEquals(adhocDefinition.getName(), jsonDefinition.getString("name")); assertEquals(adhocDefinition.getTitle(), jsonDefinition.getString("title")); assertEquals(adhocDefinition.getDescription(), jsonDefinition.getString("description")); assertEquals(adhocDefinition.getVersion(), jsonDefinition.getString("version")); assertEquals(adhocDefinition.getStartTaskDefinition().getMetadata().getName().toPrefixString(namespaceService), jsonDefinition.getString("startTaskDefinitionType")); assertTrue(jsonDefinition.has("taskDefinitions")); JSONArray tasks = result.getJSONArray("tasks"); assertTrue(tasks.length() > 1); }
Example #23
Source File: SOLRSerializerTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private void trip( SOLRTypeConverter typeConverter, String iso, String zulu) { Date testDate = ISO8601DateFormat.parse(iso); String strDate = typeConverter.INSTANCE.convert(String.class, testDate); assertEquals(zulu, strDate); }
Example #24
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 #25
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); }
Example #26
Source File: TypedPropertyValueGetter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public Serializable getValue(Object value, PropertyDefinition propDef) { if (value == null) { return null; } // before persisting check data type of property if (propDef.isMultiValued()) { return processMultiValuedType(value); } if (isBooleanProperty(propDef)) { return processBooleanValue(value); } else if (isLocaleProperty(propDef)) { return processLocaleValue(value); } else if (value instanceof String) { String valStr = (String) value; // make sure empty strings stay as empty strings, everything else // should be represented as null if (isTextProperty(propDef)) { return valStr; } if(valStr.isEmpty()) { return null; } if(isDateProperty(propDef) && !ISO8601DateFormat.isTimeComponentDefined(valStr)) { // Special handling for day-only date storage (ALF-10243) return ISO8601DateFormat.parseDayOnly(valStr, TimeZone.getDefault()); } } if (value instanceof Serializable) { return (Serializable) DefaultTypeConverter.INSTANCE.convert(propDef.getDataType(), value); } else { throw new FormException("Property values must be of a Serializable type! Value type: " + value.getClass()); } }
Example #27
Source File: AuditImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private static long getTime(String iso8601String) { return ISO8601DateFormat.parse(iso8601String.replace(" ", "+")).getTime(); }
Example #28
Source File: ReplicationModelBuilder.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Figures out the status that's one of: * New|Running|CancelRequested|Completed|Failed|Cancelled * by merging data from the action tracking service. * Will also set the start and end dates, from either the * replication definition or action tracking data, depending * on the status. */ protected void setStatus(ReplicationDefinition replicationDefinition, ExecutionDetails details, Map<String, Object> model) { // Is it currently running? if(details == null) { // It isn't running, we can use the persisted details model.put(DEFINITION_STATUS, replicationDefinition.getExecutionStatus().toString()); Date startDate = replicationDefinition.getExecutionStartDate(); if(startDate != null) { model.put(DEFINITION_STARTED_AT, ISO8601DateFormat.format(startDate)); } else { model.put(DEFINITION_STARTED_AT, null); } Date endDate = replicationDefinition.getExecutionEndDate(); if(endDate != null) { model.put(DEFINITION_ENDED_AT, ISO8601DateFormat.format(endDate)); } else { model.put(DEFINITION_ENDED_AT, null); } // It isn't running model.put(DEFINITION_RUNNING_ACTION_ID, null); return; } // As it is running / about to run, return the // details of the running/pending version if(details.isCancelRequested()) { model.put(DEFINITION_STATUS, "CancelRequested"); } else if(details.getStartedAt() == null) { model.put(DEFINITION_STATUS, "Pending"); } else { model.put(DEFINITION_STATUS, "Running"); } if(details.getStartedAt() != null) { model.put(DEFINITION_STARTED_AT, ISO8601DateFormat.format(details.getStartedAt())); } else { model.put(DEFINITION_STARTED_AT, null); } model.put(DEFINITION_ENDED_AT, null); model.put(DEFINITION_RUNNING_ACTION_ID, AbstractActionWebscript.getRunningId(details.getExecutionSummary())); // Since it's running / about to run, there shouldn't // be failure messages or transfer reports // If these currently exist on the model, remove them if(model.containsKey(DEFINITION_FAILURE_MESSAGE)) model.put(DEFINITION_FAILURE_MESSAGE, null); if(model.containsKey(DEFINITION_TRANSFER_LOCAL_REPORT)) model.put(DEFINITION_TRANSFER_LOCAL_REPORT, null); if(model.containsKey(DEFINITION_TRANSFER_REMOTE_REPORT)) model.put(DEFINITION_TRANSFER_REMOTE_REPORT, null); }
Example #29
Source File: ReplicationModelBuilder.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Build a model containing the full, detailed definition for the given * Replication Definition. */ protected Map<String, Object> buildDetails(ReplicationDefinition rd) { Map<String, Object> rdm = new HashMap<String,Object>(); // Set the core details rdm.put(DEFINITION_NAME, rd.getReplicationName()); rdm.put(DEFINITION_DESCRIPTION, rd.getDescription()); rdm.put(DEFINITION_ENABLED, rd.isEnabled()); rdm.put(DEFINITION_TARGET_NAME, rd.getTargetName()); // Set the scheduling details rdm.put(DEFINITION_SCHEDULE_ENABLED, rd.isSchedulingEnabled()); if(rd.isSchedulingEnabled()) { rdm.put(DEFINITION_SCHEDULE_START, ISO8601DateFormat.format(rd.getScheduleStart())); rdm.put(DEFINITION_SCHEDULE_COUNT, rd.getScheduleIntervalCount()); if(rd.getScheduleIntervalPeriod() != null) { rdm.put(DEFINITION_SCHEDULE_PERIOD, rd.getScheduleIntervalPeriod().toString()); } else { rdm.put(DEFINITION_SCHEDULE_PERIOD, null); } } // Set the details of the previous run // These will be null'd out later if replication is in progress rdm.put(DEFINITION_FAILURE_MESSAGE, rd.getExecutionFailureMessage()); rdm.put(DEFINITION_TRANSFER_LOCAL_REPORT, rd.getLocalTransferReport()); rdm.put(DEFINITION_TRANSFER_REMOTE_REPORT, rd.getRemoteTransferReport()); // Do the status // Includes start+end times, and running action details setStatus(rd, rdm); // Only include the payload entries that still exist // Otherwise the freemarker layer gets upset about deleted nodes List<NodeRef> payload = new ArrayList<NodeRef>(); for(NodeRef node : rd.getPayload()) { if(nodeService.exists(node)) payload.add(node); } rdm.put(DEFINITION_PAYLOAD, payload); // Save in the usual way Map<String, Object> model = new HashMap<String,Object>(); model.put(MODEL_DATA_ITEM, rdm); return model; }
Example #30
Source File: AbstractReplicationWebscript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Updates properties on the definition, based on the JSON. * Doesn't save the definition * Doesn't change the name */ protected void updateDefinitionProperties(ReplicationDefinition replicationDefinition, JSONObject json) throws JSONException { if(json.has("description")) { String description = json.getString("description"); replicationDefinition.setDescription(description); } if(json.has("targetName")) { String targetName = json.getString("targetName"); replicationDefinition.setTargetName(targetName); } if(json.has("enabled")) { boolean enabled = json.getBoolean("enabled"); replicationDefinition.setEnabled(enabled); } if(json.has("payload")) { replicationDefinition.getPayload().clear(); JSONArray payload = json.getJSONArray("payload"); for(int i=0; i<payload.length(); i++) { String node = payload.getString(i); replicationDefinition.getPayload().add( new NodeRef(node) ); } } // Now for the scheduling parts if(json.has("schedule") && !json.isNull("schedule")) { // Turn on scheduling, if not already enabled replicationService.enableScheduling(replicationDefinition); // Update the properties JSONObject schedule = json.getJSONObject("schedule"); if(schedule.has("start") && !schedule.isNull("start")) { // Look for start:.... or start:{"iso8601":....} String startDate = schedule.getString("start"); if(schedule.get("start") instanceof JSONObject) { startDate = schedule.getJSONObject("start").getString("iso8601"); } replicationDefinition.setScheduleStart( ISO8601DateFormat.parse(startDate) ); } else { replicationDefinition.setScheduleStart(null); } if(schedule.has("intervalPeriod") && !schedule.isNull("intervalPeriod")) { replicationDefinition.setScheduleIntervalPeriod( IntervalPeriod.valueOf(schedule.getString("intervalPeriod")) ); } else { replicationDefinition.setScheduleIntervalPeriod(null); } if(schedule.has("intervalCount") && !schedule.isNull("intervalCount")) { replicationDefinition.setScheduleIntervalCount( schedule.getInt("intervalCount") ); } else { replicationDefinition.setScheduleIntervalCount(null); } } else { // Disable scheduling replicationService.disableScheduling(replicationDefinition); } }