use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class VirtualCheckOutCheckInServiceExtensionTest method testAssocsReferences.
@Test
public void testAssocsReferences() throws Exception {
checkOutCheckInService.checkout(originalContentNodeRef);
NodeRef workingCopyVirtualContext = nodeService.getChildByName(node, ContentModel.ASSOC_CONTAINS, PROP_WORKING_COPY_NAME);
// test target association reference
List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(originalContentNodeRef, ContentModel.ASSOC_WORKING_COPY_LINK);
assertNotNull(targetAssocs);
assertEquals(1, targetAssocs.size());
assertEquals(workingCopyVirtualContext, targetAssocs.get(0).getTargetRef());
// test source association reference
List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(workingCopyVirtualContext, ContentModel.ASSOC_WORKING_COPY_LINK);
assertNotNull(sourceAssocs);
assertEquals(1, sourceAssocs.size());
assertEquals(originalContentNodeRef, sourceAssocs.get(0).getSourceRef());
checkOutCheckInService.cancelCheckout(workingCopyVirtualContext);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class DiscussionServiceImplTest method alf_9460.
/**
* Tests that "fm:post" content is not archived.
*/
@Test
public void alf_9460() {
TopicInfo siteTopic;
TopicInfo nodeTopic;
PostInfo post;
PostInfo reply;
// Nothing to start with
PagingResults<TopicInfo> results = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, new PagingRequest(10));
assertEquals(0, results.getPage().size());
results = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, new PagingRequest(10));
assertEquals(0, results.getPage().size());
// Create two topics, one node and one site based
siteTopic = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "Site Title");
nodeTopic = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "Node Title");
testNodesToTidy.add(siteTopic.getNodeRef());
testNodesToTidy.add(nodeTopic.getNodeRef());
for (TopicInfo topic : new TopicInfo[] { siteTopic, nodeTopic }) {
// Create the first post
String contents = "This Is Some Content";
post = DISCUSSION_SERVICE.createPost(topic, contents);
// Add a reply
String reply1Contents = "Reply Contents";
reply = DISCUSSION_SERVICE.createReply(post, reply1Contents);
List<AssociationRef> assocs = PUBLIC_NODE_SERVICE.getTargetAssocs(reply.getNodeRef(), ContentModel.ASSOC_REFERENCES);
// check that reply has an association with original post
assertNotNull(assocs);
assertEquals(1, assocs.size());
assertEquals(post.getNodeRef(), assocs.get(0).getTargetRef());
// delete the original post
DISCUSSION_SERVICE.deletePost(post);
// check that post was deleted
assertFalse(PUBLIC_NODE_SERVICE.exists(post.getNodeRef()));
// check that associations to the original post was also deleted
assocs = PUBLIC_NODE_SERVICE.getTargetAssocs(reply.getNodeRef(), ContentModel.ASSOC_REFERENCES);
assertNotNull(assocs);
assertEquals(0, assocs.size());
}
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class CopyServiceImplTest method testRelativeLinks.
/**
* Test that realtive links between nodes are restored once the copy is completed
*/
public void testRelativeLinks() {
QName nodeOneAssocName = QName.createQName("{test}nodeOne");
QName nodeTwoAssocName = QName.createQName("{test}nodeTwo");
QName nodeThreeAssocName = QName.createQName("{test}nodeThree");
QName nodeFourAssocName = QName.createQName("{test}nodeFour");
NodeRef nodeNotCopied = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, nodeOneAssocName, TEST_TYPE_QNAME).getChildRef();
NodeRef nodeOne = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, nodeOneAssocName, TEST_TYPE_QNAME).getChildRef();
NodeRef nodeTwo = nodeService.createNode(nodeOne, TEST_CHILD_ASSOC_TYPE_QNAME, nodeTwoAssocName, TEST_TYPE_QNAME).getChildRef();
NodeRef nodeThree = nodeService.createNode(nodeTwo, TEST_CHILD_ASSOC_TYPE_QNAME, nodeThreeAssocName, TEST_TYPE_QNAME).getChildRef();
NodeRef nodeFour = nodeService.createNode(nodeOne, TEST_CHILD_ASSOC_TYPE_QNAME, nodeFourAssocName, TEST_TYPE_QNAME).getChildRef();
nodeService.addChild(nodeFour, nodeThree, TEST_CHILD_ASSOC_TYPE_QNAME, TEST_CHILD_ASSOC_QNAME);
nodeService.createAssociation(nodeTwo, nodeThree, TEST_ASSOC_TYPE_QNAME);
nodeService.createAssociation(nodeTwo, nodeNotCopied, TEST_ASSOC_TYPE_QNAME);
// Make node one actionable with a rule to copy nodes into node two
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, nodeTwo);
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
Action action = actionService.createAction(CopyActionExecuter.NAME, params);
ActionCondition condition = actionService.createActionCondition(NoConditionEvaluator.NAME);
action.addActionCondition(condition);
rule.setAction(action);
ruleService.saveRule(nodeOne, rule);
// Do a deep copy
NodeRef nodeOneCopy = copyService.copy(nodeOne, rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}copiedNodeOne"), true);
NodeRef nodeTwoCopy = null;
NodeRef nodeThreeCopy = null;
NodeRef nodeFourCopy = null;
// System.out.println(
// NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
List<ChildAssociationRef> nodeOneCopyChildren = nodeService.getChildAssocs(nodeOneCopy);
assertNotNull(nodeOneCopyChildren);
assertEquals(3, nodeOneCopyChildren.size());
for (ChildAssociationRef nodeOneCopyChild : nodeOneCopyChildren) {
if (nodeOneCopyChild.getQName().equals(nodeTwoAssocName) == true) {
nodeTwoCopy = nodeOneCopyChild.getChildRef();
List<ChildAssociationRef> nodeTwoCopyChildren = nodeService.getChildAssocs(nodeTwoCopy);
assertNotNull(nodeTwoCopyChildren);
assertEquals(1, nodeTwoCopyChildren.size());
for (ChildAssociationRef nodeTwoCopyChild : nodeTwoCopyChildren) {
if (nodeTwoCopyChild.getQName().equals(nodeThreeAssocName) == true) {
nodeThreeCopy = nodeTwoCopyChild.getChildRef();
}
}
} else if (nodeOneCopyChild.getQName().equals(nodeFourAssocName) == true) {
nodeFourCopy = nodeOneCopyChild.getChildRef();
}
}
assertNotNull(nodeTwoCopy);
assertNotNull(nodeThreeCopy);
assertNotNull(nodeFourCopy);
// Check the non primary child assoc
List<ChildAssociationRef> children = nodeService.getChildAssocs(nodeFourCopy, RegexQNamePattern.MATCH_ALL, TEST_CHILD_ASSOC_QNAME);
assertNotNull(children);
assertEquals(1, children.size());
ChildAssociationRef child = children.get(0);
assertEquals(child.getChildRef(), nodeThree);
// Check the target assoc
List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeTwoCopy, TEST_ASSOC_TYPE_QNAME);
assertNotNull(assocs);
assertEquals(2, assocs.size());
AssociationRef assoc0 = assocs.get(0);
assertTrue(assoc0.getTargetRef().equals(nodeThreeCopy) || assoc0.getTargetRef().equals(nodeNotCopied));
AssociationRef assoc1 = assocs.get(1);
assertTrue(assoc1.getTargetRef().equals(nodeThreeCopy) || assoc1.getTargetRef().equals(nodeNotCopied));
// Check that the rule parameter values have been made relative
List<Rule> rules = ruleService.getRules(nodeOneCopy);
assertNotNull(rules);
assertEquals(1, rules.size());
Rule copiedRule = rules.get(0);
assertNotNull(copiedRule);
Action ruleAction = copiedRule.getAction();
assertNotNull(ruleAction);
NodeRef value = (NodeRef) ruleAction.getParameterValue(MoveActionExecuter.PARAM_DESTINATION_FOLDER);
assertNotNull(value);
assertEquals(nodeTwoCopy, value);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class MultiTServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
multiTServiceImpl = applicationContext.getBean("tenantService", MultiTServiceImpl.class);
tenantAdminService = applicationContext.getBean("tenantAdminService", TenantAdminService.class);
personService = applicationContext.getBean("PersonService", PersonService.class);
tenantService = applicationContext.getBean("tenantService", TenantService.class);
authenticationService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
transactionService = applicationContext.getBean("TransactionService", TransactionService.class);
nodeService = applicationContext.getBean("NodeService", NodeService.class);
searchService = applicationContext.getBean("SearchService", SearchService.class);
namespaceService = applicationContext.getBean("NamespaceService", NamespaceService.class);
DOMAIN = GUID.generate();
USER1 = GUID.generate();
USER2 = GUID.generate();
USER3 = GUID.generate();
USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN;
STRING = GUID.generate();
TENANT_STRING = addDomainToId(STRING, DOMAIN);
STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR;
STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR;
TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN));
TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID);
TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN));
TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME);
tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF);
childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF);
tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
mtEnabled = AuthenticationUtil.isMtEnabled();
AuthenticationUtil.setMtEnabled(false);
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class WorkingCopyAspect method onRestoreNode.
/**
* onRestoreNode policy behaviour
*
* @param nodeRef
* the node reference that was restored
*/
@SuppressWarnings("unchecked")
@Override
public void onRestoreNode(ChildAssociationRef childAssocRef) {
NodeRef workingCopyNodeRef = childAssocRef.getChildRef();
// check that node is working copy
if (nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY)) {
try {
NodeRef checkedOutNodeRef = null;
policyBehaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_AUDITABLE);
Map<QName, Serializable> workingCopyProperties = nodeService.getProperties(workingCopyNodeRef);
// get archived lock properties in order to be restored on the original node
String lockOwner = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_OWNER);
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_OWNER);
Date expiryDate = (Date) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_EXPIRY_DATE);
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_EXPIRY_DATE);
String lockTypeStr = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_TYPE);
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_TYPE);
LockType lockType = lockTypeStr != null ? LockType.valueOf(lockTypeStr) : null;
String lifetimeStr = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_LIFETIME);
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_LIFETIME);
Lifetime lifetime = lifetimeStr != null ? Lifetime.valueOf(lifetimeStr) : null;
String additionalInfo = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_ADDITIONAL_INFO);
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_ADDITIONAL_INFO);
List<AssociationRef> targetAssocList = (ArrayList<AssociationRef>) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
if (targetAssocList != null && targetAssocList.get(0) != null) {
AssociationRef targetAssoc = (AssociationRef) targetAssocList.get(0);
checkedOutNodeRef = targetAssoc.getSourceRef();
nodeService.createAssociation(targetAssoc.getSourceRef(), targetAssoc.getTargetRef(), ContentModel.ASSOC_ORIGINAL);
}
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
ArrayList<AssociationRef> sourceAssocList = (ArrayList<AssociationRef>) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
if (sourceAssocList != null && sourceAssocList.get(0) != null) {
AssociationRef sourceAssoc = (AssociationRef) sourceAssocList.get(0);
checkedOutNodeRef = sourceAssoc.getSourceRef();
nodeService.createAssociation(sourceAssoc.getSourceRef(), sourceAssoc.getTargetRef(), ContentModel.ASSOC_WORKING_COPY_LINK);
}
workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
// clean up the archived aspect and properties for working copy node
nodeService.removeAspect(workingCopyNodeRef, ContentModel.ASPECT_ARCHIVE_LOCKABLE);
nodeService.setProperties(workingCopyNodeRef, workingCopyProperties);
// restore properties on original node
nodeService.addAspect(checkedOutNodeRef, ContentModel.ASPECT_LOCKABLE, null);
Map<QName, Serializable> checkedOutNodeProperties = nodeService.getProperties(checkedOutNodeRef);
checkedOutNodeProperties.put(ContentModel.PROP_LOCK_OWNER, lockOwner);
checkedOutNodeProperties.put(ContentModel.PROP_LOCK_TYPE, lockType);
checkedOutNodeProperties.put(ContentModel.PROP_LOCK_LIFETIME, lifetime);
checkedOutNodeProperties.put(ContentModel.PROP_EXPIRY_DATE, expiryDate);
checkedOutNodeProperties.put(ContentModel.PROP_LOCK_ADDITIONAL_INFO, additionalInfo);
nodeService.setProperties(checkedOutNodeRef, checkedOutNodeProperties);
} finally {
policyBehaviourFilter.enableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_AUDITABLE);
}
}
}
Aggregations