org.alfresco.repo.jscript.ScriptNode Java Examples
The following examples show how to use
org.alfresco.repo.jscript.ScriptNode.
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: JSONConversionComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Handles the work of converting all set permissions to JSON. * * @param nodeRef NodeRef * @return JSONArray */ @SuppressWarnings("unchecked") protected JSONArray allSetPermissionsToJSON(NodeRef nodeRef) { Set<AccessPermission> acls = permissionService.getAllSetPermissions(nodeRef); JSONArray permissions = new JSONArray(); List<AccessPermission> ordered = ScriptNode.getSortedACLs(acls); for (AccessPermission permission : ordered) { StringBuilder buf = new StringBuilder(64); buf.append(permission.getAccessStatus()) .append(';') .append(permission.getAuthority()) .append(';') .append(permission.getPermission()) .append(';').append(permission.isSetDirectly() ? "DIRECT" : "INHERITED"); permissions.add(buf.toString()); } return permissions; }
Example #2
Source File: JscriptWorkflowTask.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Get the packe resources (array of noderefs) * * @return Scriptable */ public Scriptable getPackageResources() { List<NodeRef> contents = workflowService.getPackageContents(task.getId()); List<ScriptNode> resources = new ArrayList<ScriptNode>(contents.size()); Collection<QName> allowedTypes = getAllowedPackageResourceTypes(); for (NodeRef node : contents) { if (isValidResource(node, allowedTypes)) { ScriptNode scriptNode = new ScriptNode(node, serviceRegistry, getScope()); resources.add(scriptNode); } } return Context.getCurrentContext().newArray(getScope(), resources.toArray()); }
Example #3
Source File: JscriptWorkflowDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Start workflow instance from workflow definition * * @param workflowPackage workflow package node to 'attach' to the new workflow * instance * @param properties Associative array of properties used to populate the * start task properties * @return the initial workflow path */ @SuppressWarnings("unchecked") public JscriptWorkflowPath startWorkflow(ScriptNode workflowPackage, Object properties) { WorkflowService workflowService = this.serviceRegistry.getWorkflowService(); // if properties object is a scriptable object, then extract property name/value pairs // into property Map<QName, Serializable>, otherwise leave property map as null Map<QName, Serializable> workflowParameters = null; if (properties instanceof ScriptableObject) { ScriptableObject scriptableProps = (ScriptableObject)properties; workflowParameters = new HashMap<QName, Serializable>(scriptableProps.getIds().length); extractScriptablePropertiesToMap(scriptableProps, workflowParameters); } // attach given workflow package node if it is not null if (workflowPackage != null) { if (workflowParameters == null) { workflowParameters = new HashMap<QName, Serializable>(1); } workflowParameters.put(WorkflowModel.ASSOC_PACKAGE, getValueConverter().convertValueForRepo(workflowPackage)); } // provide a default context, if one is not specified Serializable context = workflowParameters.get(WorkflowModel.PROP_CONTEXT); if (context == null) { workflowParameters.put(WorkflowModel.PROP_CONTEXT, workflowPackage.getNodeRef()); } WorkflowPath cmrWorkflowPath = workflowService.startWorkflow(this.id, workflowParameters); return new JscriptWorkflowPath(cmrWorkflowPath, this.serviceRegistry, this.scope); }
Example #4
Source File: ScriptRenditionService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method gets all the renditions of the specified node. * * @param node the source node * @return an array of the renditions. * @see org.alfresco.service.cmr.rendition.RenditionService#getRenditions(org.alfresco.service.cmr.repository.NodeRef) */ public ScriptNode[] getRenditions(ScriptNode node) { List<ChildAssociationRef> renditions = this.renditionService.getRenditions(node.getNodeRef()); ScriptNode[] renditionObjs = new ScriptNode[renditions.size()]; for (int i = 0; i < renditions.size(); i++) { renditionObjs[i] = new ScriptNode(renditions.get(i).getChildRef(), serviceRegistry); } return renditionObjs; }
Example #5
Source File: ScriptReplicationDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ScriptNode[] getPayload() { List<NodeRef> payload = getReplicationDefinition().getPayload(); ScriptNode[] nodes = new ScriptNode[payload.size()]; for(int i=0; i<nodes.length; i++) { nodes[i] = new ScriptNode(payload.get(i), services); } return nodes; }
Example #6
Source File: ScriptTaggingService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get a tag by name if available in a store * * @param store store reference * @param tag tag name * @return ScriptNode tag node, or null if not found */ public ScriptNode getTag(String store, String tag) { StoreRef storeRef = new StoreRef(store); NodeRef result = this.serviceRegistry.getTaggingService().getTagNodeRef(storeRef, tag); if (result != null) { return new ScriptNode(result, this.serviceRegistry, this.getScope()); } return null; }
Example #7
Source File: ScriptTaggingService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Create a tag in a given store * * @param store store reference * @param tag tag name * @return ScriptNode newly created tag node, or null if unable to create */ public ScriptNode createTag(String store, String tag) { StoreRef storeRef = new StoreRef(store); NodeRef result = this.serviceRegistry.getTaggingService().createTag(storeRef, tag); if (result != null) { return new ScriptNode(result, this.serviceRegistry); } return null; }
Example #8
Source File: WorkflowObjectFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public WorkflowInstance createInstance(String id, WorkflowDefinition definition, Map<String, Object> variables, boolean isActive, Date startDate, Date endDate) { String actualId = buildGlobalId(id); String description = (String) getVariable(variables, WorkflowModel.PROP_WORKFLOW_DESCRIPTION); NodeRef initiator = null; ScriptNode initiatorSN= (ScriptNode) getVariable(variables, WorkflowConstants.PROP_INITIATOR); if(initiatorSN != null) { initiator = initiatorSN.getNodeRef(); } NodeRef context = getNodeVariable(variables, WorkflowModel.PROP_CONTEXT); NodeRef workflowPackage= getNodeVariable(variables, WorkflowModel.ASSOC_PACKAGE); WorkflowInstance workflowInstance = new WorkflowInstance( actualId, definition, description, initiator, workflowPackage, context, isActive, startDate, endDate); workflowInstance.priority = (Integer) getVariable(variables, WorkflowModel.PROP_WORKFLOW_PRIORITY); Date dueDate = (Date) getVariable(variables, WorkflowModel.PROP_WORKFLOW_DUE_DATE); if(dueDate != null) { workflowInstance.dueDate = dueDate; } return workflowInstance; }
Example #9
Source File: WorkflowObjectFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private NodeRef getNodeVariable(Map<String, Object> variables, QName qName) { Object obj = getVariable(variables, qName); if (obj==null) { return null; } if(obj instanceof ScriptNode) { ScriptNode scriptNode = (ScriptNode) obj; return scriptNode.getNodeRef(); } String message = "Variable "+qName+" should be of type ScriptNode but was "+obj.getClass(); throw new WorkflowException(message); }
Example #10
Source File: ScriptNodeVariableType.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean isAbleToStore(Object value) { if (value == null) { return true; } return ScriptNode.class.isAssignableFrom(value.getClass()); }
Example #11
Source File: ScriptNodeVariableType.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Object getValue(ValueFields valueFields) { ScriptNode scriptNode = null; String nodeRefString = valueFields.getTextValue(); if (nodeRefString != null) { scriptNode = new ActivitiScriptNode(new NodeRef(nodeRefString), serviceRegistry); } return scriptNode; }
Example #12
Source File: ScriptRenditionService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method gets all the renditions of the specified node filtered by * MIME-type prefix. Renditions whose MIME-type string startsWith the prefix * will be returned. * * @param node the source node for the renditions * @param mimeTypePrefix a prefix to check against the rendition MIME-types. * This must not be null and must not be an empty String * @return an array of the filtered renditions. * @see org.alfresco.service.cmr.rendition.RenditionService#getRenditions(org.alfresco.service.cmr.repository.NodeRef) */ public ScriptNode[] getRenditions(ScriptNode node, String mimeTypePrefix) { List<ChildAssociationRef> renditions = this.renditionService.getRenditions(node.getNodeRef(), mimeTypePrefix); ScriptNode[] results = new ScriptNode[renditions.size()]; for (int i = 0; i < renditions.size(); i++) { results[i] = new ScriptNode(renditions.get(i).getChildRef(), serviceRegistry); } return results; }
Example #13
Source File: InvitationServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private String getPackageRef(Map<String, Object> executionVariables) { String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_"); ScriptNode packageNode = (ScriptNode) executionVariables.get(packageName); String packageRef = packageNode.getNodeRef().toString(); return packageRef; }
Example #14
Source File: ScriptAuthorityServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testBasics() { // Should return the same count for the root groups int count = pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size(); ScriptGroup[] groups = service.getAllRootGroups(); assertEquals(count, groups.length); // And our test ones are in there ScriptGroup groupA = null; ScriptGroup groupB = null; ScriptGroup groupC = null; for(ScriptGroup group : groups) { if (group.getShortName().equals(GROUP_A)) groupA = group; if (group.getShortName().equals(GROUP_B)) groupB = group; if (group.getShortName().equals(GROUP_C)) groupC = group; } assertNotNull(GROUP_A + " not found in " + Arrays.toString(groups), groupA); assertNotNull(GROUP_B + " not found in " + Arrays.toString(groups), groupB); assertNotNull(GROUP_C + " not found in " + Arrays.toString(groups), groupC); // Check group A in more detail assertEquals(GROUP_A, groupA.getShortName()); assertEquals(GROUP_A, groupA.getDisplayName()); assertEquals(GROUP_A_FULL, groupA.getFullName()); // return the NodeRef for the group and check ScriptNode groupANode = groupA.getGroupNode(); assertEquals(groupA.getDisplayName(), groupANode.getProperties().get("authorityDisplayName")); assertEquals(groupA.getFullName(), groupANode.getProperties().get("authorityName")); }
Example #15
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Test reverting from Share with changing type * see MNT-14688 * <li> * <ul>1) Create a node and a version (simulates upload a doc to Share)</ul> * <ul>2) Change the node's type to a custom with mandatory aspect</ul> * <ul>3) Create a new version via upload</ul> * <ul>4) Try to revert to original document and see if the type is reverted, too</ul> * </li> */ @SuppressWarnings("unused") @Commit @Test public void testScriptNodeRevertWithChangeType() { CheckOutCheckInService checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService"); // Create a versionable node NodeRef versionableNode = createNewVersionableNode(); Version version1 = createVersion(versionableNode); //Set new type nodeService.setType(versionableNode, TEST_TYPE_WITH_MANDATORY_ASPECT_QNAME); // Create a new version NodeRef checkedOut = checkOutCheckInService.checkout(versionableNode); ContentWriter contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true); assertNotNull(contentWriter); contentWriter.putContent(UPDATED_CONTENT_1); nodeService.setProperty(checkedOut, PROP_1, VALUE_1); checkOutCheckInService.checkin(checkedOut, null, contentWriter.getContentUrl(), false); Version version2 = createVersion(versionableNode); // Create a ScriptNode as used in Share ServiceRegistry services = applicationContext.getBean(ServiceRegistry.class); ScriptNode scriptNode = new ScriptNode(versionableNode, services); assertEquals("0.2", nodeService.getProperty(scriptNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL)); assertEquals(TEST_TYPE_WITH_MANDATORY_ASPECT_QNAME, nodeService.getType(scriptNode.getNodeRef())); // Revert to version1 ScriptNode newNode = scriptNode.revert("History", false, version1.getVersionLabel()); assertEquals("0.3", nodeService.getProperty(newNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL)); assertEquals(TEST_TYPE_QNAME, nodeService.getType(newNode.getNodeRef())); }
Example #16
Source File: ScriptCounterSignService.java From CounterSign with GNU Affero General Public License v3.0 | 5 votes |
/** * Get a nodeRef string for the user's keystore node * * @param user * @return */ public ScriptNode getKeystoreNode(String user) { NodeRef keystore = counterSignService.getSignatureArtifact(user, CounterSignSignatureModel.ASSOC_SIGNERKEYSTORE); if(keystore != null) { return new ScriptNode(keystore, serviceRegistry); } else { return null; } }
Example #17
Source File: ScriptCounterSignService.java From CounterSign with GNU Affero General Public License v3.0 | 5 votes |
/** * Get a nodeRef string for the user's signature image * * @param user * @return */ public ScriptNode getSignatureImageNode(String user) { NodeRef image = counterSignService.getSignatureArtifact(user, CounterSignSignatureModel.ASSOC_SIGNERSIGNATUREIMAGE); if(image != null) { return new ScriptNode(image, serviceRegistry); } else { return null; } }
Example #18
Source File: ScriptCounterSignService.java From CounterSign with GNU Affero General Public License v3.0 | 5 votes |
/** * Get a nodeRef string for the user's signature image * * @param user * @return */ public ScriptNode getPublicKeyNode(String user) { NodeRef publicKey= counterSignService.getSignatureArtifact(user, CounterSignSignatureModel.ASSOC_SIGNERPUBLICKEY); if(publicKey != null) { return new ScriptNode(publicKey, serviceRegistry); } else { return null; } }
Example #19
Source File: ScriptReplicationDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void setPayload(ScriptNode[] payloadNodes) { List<NodeRef> payload = getReplicationDefinition().getPayload(); payload.clear(); for(ScriptNode payloadNode : payloadNodes) { payload.add(payloadNode.getNodeRef()); } }
Example #20
Source File: Site.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a new site container * * @param componentId component id * @param folderType folder type to create * @return ScriptNode the created container */ public ScriptNode createContainer(final String componentId, final String folderType, final Object permissions) { final NodeRef containerNodeRef = this.createContainerImpl(componentId, folderType, permissions); if (Site.this.serviceRegistry.getPermissionService().hasPermission(containerNodeRef, PermissionService.READ_PROPERTIES) == AccessStatus.ALLOWED) { return getContainer(componentId); } else { // current user has no access. return null; } }
Example #21
Source File: Site.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method creates a container of the specified id and type, sets the cm:description * on that container node to the specified value and saves the container node updates to the repository. * All of this is run as system. * * @param containerId an id for the container node. * @param containerType the type for the container node. * @param description a value for the cm:description property on the container node. * * @return the newly created and saved container {@link ScriptNode}. * @since 3.4 */ public ScriptNode createAndSaveContainer(String containerId, String containerType, final String description) { // Implementation node. See ALF-4282 for details. // // The container for the "data lists" page within a Share site is lazily created the first time // that a user navigates to that page. However if the first Share user to look at the data lists // page for a site is not a site manager then they will not have the necessary permissions to // create the container node. // For this reason we need to create the node, set its cm:description and save those changes // as system. // The container creation is already run as system, so we don't need to double-wrap this first call // in a RunAs class. final ScriptNode result = this.createContainer(containerId, containerType); if (result == null) { return null; } AuthenticationUtil.runAs(new RunAsWork<Void>() { public Void doWork() throws Exception { serviceRegistry.getNodeService().setProperty(result.getNodeRef(), ContentModel.PROP_DESCRIPTION, description); result.save(); return null; } }, AuthenticationUtil.SYSTEM_USER_NAME); return result; }
Example #22
Source File: Site.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get a map of the sites custom properties * * @return map of names and values */ public ScriptableQNameMap<String, CustomProperty> getCustomProperties() { if (this.customProperties == null) { // create the custom properties map ScriptNode siteNode = new ScriptNode(this.siteInfo.getNodeRef(), this.serviceRegistry); // set the scope, for use when converting props to javascript objects siteNode.setScope(scope); this.customProperties = new ContentAwareScriptableQNameMap<String, CustomProperty>(siteNode, this.serviceRegistry); Map<QName, Serializable> props = siteInfo.getCustomProperties(); for (QName qname : props.keySet()) { // get the property value Serializable propValue = props.get(qname); // convert the value NodeValueConverter valueConverter = siteNode.new NodeValueConverter(); Serializable value = valueConverter.convertValueForScript(qname, propValue); // get the type and label information from the dictionary String title = null; String type = null; PropertyDefinition propDef = this.serviceRegistry.getDictionaryService().getProperty(qname); if (propDef != null) { type = propDef.getDataType().getName().toString(); title = propDef.getTitle(this.serviceRegistry.getDictionaryService()); } // create the custom property and add to the map CustomProperty customProp = new CustomProperty(qname.toString(), value, type, title); this.customProperties.put(qname.toString(), customProp); } } return this.customProperties; }
Example #23
Source File: Site.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Reset any permissions that have been set on the node. * <p> * All permissions will be deleted and the node set to inherit permissions. * * @param node node */ public void resetAllPermissions(ScriptNode node) { final NodeRef nodeRef = node.getNodeRef(); // ensure the user has permission to Change Permissions final PermissionService permissionService = serviceRegistry.getPermissionService(); if (permissionService.hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS).equals(AccessStatus.ALLOWED)) { AuthenticationUtil.runAs(new RunAsWork<Void>() { public Void doWork() throws Exception { // Ensure node isn't inheriting permissions from an ancestor before deleting if (!permissionService.getInheritParentPermissions(nodeRef)) { permissionService.deletePermissions(nodeRef); permissionService.setInheritParentPermissions(nodeRef, true); } return null; } }, AuthenticationUtil.SYSTEM_USER_NAME); } else { throw new AlfrescoRuntimeException("You do not have the authority to update permissions on this node."); } }
Example #24
Source File: ActivitiNodeConverter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ @Override public NodeRef convertToNode(Object toConvert) { return ((ScriptNode)toConvert).getNodeRef(); }
Example #25
Source File: ScriptReplicationDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void executeImpl(ScriptNode node) { ReplicationDefinition replicationDefinition = getReplicationDefinition(); replicationService.replicate(replicationDefinition); }
Example #26
Source File: RestVariableHelper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public QName extractTypeFromValue(Object value) { QName type = null; if(value instanceof Collection<?>) { Collection<?> collection = (Collection<?>) value; if(collection.size() > 0) { type = extractTypeFromValue(collection.iterator().next()); } } else { if(value instanceof String) { type = DataTypeDefinition.TEXT; } else if(value instanceof Integer) { type = DataTypeDefinition.INT; } else if(value instanceof Long) { type = DataTypeDefinition.LONG; } else if(value instanceof Double) { type = DataTypeDefinition.DOUBLE; } else if(value instanceof Float) { type = DataTypeDefinition.FLOAT; } else if(value instanceof Date) { type = DataTypeDefinition.DATETIME; } else if(value instanceof Boolean) { type = DataTypeDefinition.BOOLEAN; } else if(value instanceof QName) { type = DataTypeDefinition.QNAME; } else if(value instanceof NodeRef || value instanceof ScriptNode) { type = DataTypeDefinition.NODE_REF; } } if(type == null) { // Type cannot be determined, revert to default for unknown types type = DataTypeDefinition.ANY; } return type; }
Example #27
Source File: RestVariableHelper.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
protected Object getSafePropertyValue(Object value) { if (value instanceof NodeRef) { return value.toString(); } else if (value instanceof ScriptNode) { NodeRef ref = ((ScriptNode) value).getNodeRef(); try { QName nodeQName = nodeService.getType(ref); if (ContentModel.TYPE_PERSON.equals(nodeQName)) { // Extract username from person and return return (String) nodeService.getProperty(ref, ContentModel.PROP_USERNAME); } else if (ContentModel.TYPE_AUTHORITY_CONTAINER.equals(nodeQName)) { // Extract name from group and return return (String) nodeService.getProperty(ref, ContentModel.PROP_AUTHORITY_NAME); } else { return ((ScriptNode) value).getNodeRef().toString(); } } catch (Exception e) { // node ref QName could not be found, just creating a String return ((ScriptNode) value).getNodeRef().toString(); } } else if (value instanceof QName) { return ((QName) value).toPrefixString(namespaceService); } else if (value instanceof Collection<?>) { if (value != null) { List<Object> resultValues = new ArrayList<Object>(); for (Object itemValue : (Collection<?>) value) { resultValues.add(getSafePropertyValue(itemValue)); } value = resultValues; } } return value; }
Example #28
Source File: ActivitiWorkflowComponentTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testStartWorkflow() throws Exception { WorkflowDefinition def = deployTestTaskDefinition(); // Fill a map of default properties to start the workflow with Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); Date dueDate = Calendar.getInstance().getTime(); properties.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "description123"); properties.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate); properties.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 2); // properties.put(WorkflowModel.ASSOC_PACKAGE, null); // properties.put(WorkflowModel.PROP_CONTEXT, null); // Call the start method WorkflowPath path = workflowEngine.startWorkflow(def.getId(), properties); assertNotNull("The workflow path is null!", path); String executionId = BPMEngineRegistry.getLocalId(path.getId()); Execution execution = runtime.createExecutionQuery() .executionId(executionId) .singleResult(); assertNotNull("No execution was created int he DB!", execution); WorkflowInstance instance = path.getInstance(); assertNotNull("The workflow instance is null!",instance); String procInstanceId = BPMEngineRegistry.getLocalId(instance.getId()); ProcessInstance procInstance = runtime.createProcessInstanceQuery() .processInstanceId(procInstanceId) .singleResult(); assertNotNull("No process instance was created!", procInstance); WorkflowNode node = path.getNode(); assertNotNull("The workflow node is null!", node); String nodeName = node.getName(); assertEquals("task", nodeName); // Check if company home is added as variable and can be fetched ScriptNode companyHome = (ScriptNode) runtime.getVariable(procInstanceId, "companyhome"); assertNotNull(companyHome); assertEquals("companyHome", companyHome.getNodeRef().getStoreRef().getIdentifier()); // Check if the initiator is added as variable ScriptNode initiator = (ScriptNode) runtime.getVariable(procInstanceId, "initiator"); assertNotNull(initiator); assertEquals("admin", initiator.getNodeRef().getStoreRef().getIdentifier()); // Check if the initiator home is also set as variable ScriptNode initiatorHome = (ScriptNode) runtime.getVariable(procInstanceId, "initiatorhome"); assertNotNull(initiatorHome); assertEquals("admin-home", initiatorHome.getNodeRef().getStoreRef().getIdentifier()); // Check if start-date is set and no end-date is set assertNotNull(path.getInstance().getStartDate()); assertNull(path.getInstance().getEndDate()); // Also check if the task that is created, has all default properties initialised Task task = taskService.createTaskQuery().processInstanceId(procInstanceId).singleResult(); assertNotNull("Task should have been created", task); assertEquals("task", task.getTaskDefinitionKey()); String defaultSetVariable = (String) taskService.getVariableLocal(task.getId(), "test_myProp"); assertEquals("Default value", defaultSetVariable); // Also check default value of task description is taken from WF-porps assertEquals("description123", task.getDescription()); }
Example #29
Source File: VersionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Test reverting from Share */ @SuppressWarnings("unused") @Commit @Test public void testScriptNodeRevert() { CheckOutCheckInService checkOutCheckIn = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService"); // Create a versionable node NodeRef versionableNode = createNewVersionableNode(); NodeRef checkedOut = checkOutCheckIn.checkout(versionableNode); Version versionC1 = createVersion(checkedOut); // Create a new, first proper version ContentWriter contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true); assertNotNull(contentWriter); contentWriter.putContent(UPDATED_CONTENT_1); nodeService.setProperty(checkedOut, PROP_1, VALUE_1); checkOutCheckIn.checkin(checkedOut, null, contentWriter.getContentUrl(), false); Version version1 = createVersion(versionableNode); checkedOut = checkOutCheckIn.checkout(versionableNode); // Create another new version contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true); assertNotNull(contentWriter); contentWriter.putContent(UPDATED_CONTENT_2); nodeService.setProperty(checkedOut, PROP_1, VALUE_2); checkOutCheckIn.checkin(checkedOut, null, contentWriter.getContentUrl(), false); Version version2 = createVersion(versionableNode); checkedOut = checkOutCheckIn.checkout(versionableNode); // Check we're now up to two versions // (The version created on the working copy doesn't count) VersionHistory history = versionService.getVersionHistory(versionableNode); assertEquals(version2.getVersionLabel(), history.getHeadVersion().getVersionLabel()); assertEquals(version2.getVersionedNodeRef(), history.getHeadVersion().getVersionedNodeRef()); assertEquals(2, history.getAllVersions().size()); Version[] versions = history.getAllVersions().toArray(new Version[2]); assertEquals("0.2", versions[0].getVersionLabel()); assertEquals("0.1", versions[1].getVersionLabel()); // Add yet another version contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true); assertNotNull(contentWriter); contentWriter.putContent(UPDATED_CONTENT_3); nodeService.setProperty(checkedOut, PROP_1, VALUE_3); checkOutCheckIn.checkin(checkedOut, null, contentWriter.getContentUrl(), false); Version version3 = createVersion(versionableNode); // Verify that the version labels are as we expect them to be history = versionService.getVersionHistory(versionableNode); assertEquals(version3.getVersionLabel(), history.getHeadVersion().getVersionLabel()); assertEquals(version3.getVersionedNodeRef(), history.getHeadVersion().getVersionedNodeRef()); assertEquals(3, history.getAllVersions().size()); versions = history.getAllVersions().toArray(new Version[3]); assertEquals("0.3", versions[0].getVersionLabel()); assertEquals("0.2", versions[1].getVersionLabel()); assertEquals("0.1", versions[2].getVersionLabel()); // Create a ScriptNode as used in Share ServiceRegistry services = applicationContext.getBean(ServiceRegistry.class); ScriptNode scriptNode = new ScriptNode(versionableNode, services); assertEquals("0.3", nodeService.getProperty(scriptNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL)); assertEquals(VALUE_3, nodeService.getProperty(scriptNode.getNodeRef(), PROP_1)); // Revert to version2 // The content and properties will be the same as on Version 2, but we'll // actually be given a new version number for it ScriptNode newNode = scriptNode.revert("History", false, version2.getVersionLabel()); ContentReader contentReader = this.contentService.getReader(newNode.getNodeRef(), ContentModel.PROP_CONTENT); assertNotNull(contentReader); assertEquals(UPDATED_CONTENT_2, contentReader.getContentString()); assertEquals(VALUE_2, nodeService.getProperty(newNode.getNodeRef(), PROP_1)); // Will be a new version though - TODO Is this correct? assertEquals("0.4", nodeService.getProperty(newNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL)); // Revert to version1 newNode = scriptNode.revert("History", false, version1.getVersionLabel()); contentReader = this.contentService.getReader(newNode.getNodeRef(), ContentModel.PROP_CONTENT); assertNotNull(contentReader); assertEquals(UPDATED_CONTENT_1, contentReader.getContentString()); assertEquals(VALUE_1, nodeService.getProperty(newNode.getNodeRef(), PROP_1)); // Will be a new version though - TODO Is this correct? assertEquals("0.5", nodeService.getProperty(newNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL)); }
Example #30
Source File: ScriptExecutionDetails.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public ScriptNode getPersistedActionRef() { return new ScriptNode(details.getPersistedActionRef(), services); }