Search in sources :

Example 66 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class WorkingCopyAspect method beforeArchiveNode.

/**
 * beforeArchiveNode policy behaviour
 *
 * @param nodeRef
 *            the node reference about to be archived
 */
@Override
public void beforeArchiveNode(NodeRef workingCopyNodeRef) {
    NodeRef checkedOutNodeRef = checkOutCheckInService.getCheckedOut(workingCopyNodeRef);
    if (checkedOutNodeRef != null) {
        try {
            policyBehaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_AUDITABLE);
            if (nodeService.hasAspect(checkedOutNodeRef, ContentModel.ASPECT_LOCKABLE)) {
                Map<QName, Serializable> checkedOutNodeProperties = nodeService.getProperties(checkedOutNodeRef);
                Map<QName, Serializable> workingCopyProperties = nodeService.getProperties(workingCopyNodeRef);
                Long nodeId = nodeDAO.getNodePair(workingCopyNodeRef).getFirst();
                // get lock properties from checked out node and set them on working copy node in order to be available for restore
                String lockOwner = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_OWNER);
                Date expiryDate = (Date) checkedOutNodeProperties.get(ContentModel.PROP_EXPIRY_DATE);
                String lockTypeStr = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_TYPE);
                LockType lockType = lockTypeStr != null ? LockType.valueOf(lockTypeStr) : null;
                String lifetimeStr = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_LIFETIME);
                Lifetime lifetime = lifetimeStr != null ? Lifetime.valueOf(lifetimeStr) : null;
                String additionalInfo = (String) checkedOutNodeProperties.get(ContentModel.PROP_LOCK_ADDITIONAL_INFO);
                nodeService.addAspect(workingCopyNodeRef, ContentModel.ASPECT_ARCHIVE_LOCKABLE, null);
                workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_OWNER, lockOwner);
                workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_TYPE, lockType);
                workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_LIFETIME, lifetime);
                workingCopyProperties.put(ContentModel.PROP_ARCHIVED_EXPIRY_DATE, expiryDate);
                workingCopyProperties.put(ContentModel.PROP_ARCHIVED_LOCK_ADDITIONAL_INFO, additionalInfo);
                // Target associations
                Collection<Pair<Long, AssociationRef>> targetAssocs = nodeDAO.getTargetNodeAssocs(nodeId, null);
                for (Pair<Long, AssociationRef> targetAssocPair : targetAssocs) {
                    if (ContentModel.ASSOC_ORIGINAL.equals(targetAssocPair.getSecond().getTypeQName())) {
                        workingCopyProperties.put(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS, targetAssocPair.getSecond());
                    }
                }
                // Source associations
                Collection<Pair<Long, AssociationRef>> sourceAssocs = nodeDAO.getSourceNodeAssocs(nodeId, null);
                for (Pair<Long, AssociationRef> sourceAssocPair : sourceAssocs) {
                    if (ContentModel.ASSOC_WORKING_COPY_LINK.equals(sourceAssocPair.getSecond().getTypeQName())) {
                        workingCopyProperties.put(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS, sourceAssocPair.getSecond());
                    }
                }
                // update working copy node properties
                nodeService.setProperties(workingCopyNodeRef, workingCopyProperties);
            }
        } finally {
            policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) LockType(org.alfresco.service.cmr.lock.LockType) Date(java.util.Date) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Lifetime(org.alfresco.repo.lock.mem.Lifetime) Pair(org.alfresco.util.Pair)

Example 67 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class PolicyFactory method convertMTArgs.

/**
 * Convert each of the arguments to the spoofed (no tenant prefix) reference.
 *
 * Converts arguments of Type NodeRef to base name etc.
 *
 * @param args list of non final arguments - the arguments are updated in place
 */
protected static void convertMTArgs(Object[] args) {
    // Convert each of the arguments to the spoofed (no tenant prefix) reference
    for (int i = 0; i < args.length; i++) {
        Object arg = args[i];
        Object newArg = arg;
        if (arg == null) {
        // No conversion possible
        }
        if (arg instanceof StoreRef) {
            StoreRef ref = (StoreRef) arg;
            newArg = tenantService.getBaseName(ref);
        } else if (arg instanceof NodeRef) {
            NodeRef ref = (NodeRef) arg;
            newArg = tenantService.getBaseName(ref);
        } else if (arg instanceof ChildAssociationRef) {
            ChildAssociationRef ref = (ChildAssociationRef) arg;
            newArg = tenantService.getBaseName(ref);
        } else if (arg instanceof AssociationRef) {
            AssociationRef ref = (AssociationRef) arg;
            newArg = tenantService.getBaseName(ref);
        }
        // Substitute the new value
        args[i] = newArg;
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 68 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class DocumentPropertiesDialog method save.

/**
 * Event handler used to save the edited properties back to the repository
 *
 * @return The outcome
 */
public String save() {
    String outcome = "cancel";
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
        tx.begin();
        NodeRef nodeRef = this.browseBean.getDocument().getNodeRef();
        Map<String, Object> props = this.editableNode.getProperties();
        // get the name and move the node as necessary
        String name = (String) props.get(ContentModel.PROP_NAME);
        if (name != null) {
            getFileFolderService().rename(nodeRef, name);
        }
        Map<QName, Serializable> properties = getNodeService().getProperties(nodeRef);
        // we need to put all the properties from the editable bag back into
        // the format expected by the repository
        // Deal with the special mimetype property for ContentData
        String mimetype = (String) props.get(TEMP_PROP_MIMETYPE);
        if (mimetype != null) {
            // remove temporary prop from list so it isn't saved with the others
            props.remove(TEMP_PROP_MIMETYPE);
            ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT);
            if (contentData != null) {
                contentData = ContentData.setMimetype(contentData, mimetype);
                props.put(ContentModel.PROP_CONTENT.toString(), contentData);
            }
        }
        // Deal with the special encoding property for ContentData
        String encoding = (String) props.get(TEMP_PROP_ENCODING);
        if (encoding != null) {
            // remove temporary prop from list so it isn't saved with the others
            props.remove(TEMP_PROP_ENCODING);
            ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT);
            if (contentData != null) {
                contentData = ContentData.setEncoding(contentData, encoding);
                props.put(ContentModel.PROP_CONTENT.toString(), contentData);
            }
        }
        // extra and deal with the Author prop if the aspect has not been applied yet
        String author = (String) props.get(ContentModel.PROP_AUTHOR);
        if (author != null && author.length() != 0) {
            // add aspect if required
            if (getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false) {
                Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
                authorProps.put(ContentModel.PROP_AUTHOR, author);
                getNodeService().addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
            }
        // else it will get updated in the later setProperties() call
        }
        // deal with adding the "titled" aspect if required
        String title = (String) props.get(ContentModel.PROP_TITLE);
        String description = (String) props.get(ContentModel.PROP_DESCRIPTION);
        if (title != null || description != null) {
            // add the aspect to be sure it's present
            getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
        // props will get added later in setProperties()
        }
        // add the remaining properties
        Iterator<String> iterProps = props.keySet().iterator();
        while (iterProps.hasNext()) {
            String propName = iterProps.next();
            QName qname = QName.createQName(propName);
            // make sure the property is represented correctly
            Serializable propValue = (Serializable) props.get(propName);
            // check for empty strings when using number types, set to null in this case
            if ((propValue != null) && (propValue instanceof String) && (propValue.toString().length() == 0)) {
                PropertyDefinition propDef = getDictionaryService().getProperty(qname);
                if (propDef != null) {
                    if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propDef.getDataType().getName().equals(DataTypeDefinition.INT) || propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
                        propValue = null;
                    }
                }
            }
            properties.put(qname, propValue);
        }
        // send the properties back to the repository
        getNodeService().setProperties(this.browseBean.getDocument().getNodeRef(), properties);
        // we also need to persist any association changes that may have been made
        // add any associations added in the UI
        Map<String, Map<String, AssociationRef>> addedAssocs = this.editableNode.getAddedAssociations();
        for (Map<String, AssociationRef> typedAssoc : addedAssocs.values()) {
            for (AssociationRef assoc : typedAssoc.values()) {
                getNodeService().createAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
            }
        }
        // remove any association removed in the UI
        Map<String, Map<String, AssociationRef>> removedAssocs = this.editableNode.getRemovedAssociations();
        for (Map<String, AssociationRef> typedAssoc : removedAssocs.values()) {
            for (AssociationRef assoc : typedAssoc.values()) {
                getNodeService().removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
            }
        }
        // add any child associations added in the UI
        Map<String, Map<String, ChildAssociationRef>> addedChildAssocs = this.editableNode.getAddedChildAssociations();
        for (Map<String, ChildAssociationRef> typedAssoc : addedChildAssocs.values()) {
            for (ChildAssociationRef assoc : typedAssoc.values()) {
                getNodeService().addChild(assoc.getParentRef(), assoc.getChildRef(), assoc.getTypeQName(), assoc.getTypeQName());
            }
        }
        // remove any child association removed in the UI
        Map<String, Map<String, ChildAssociationRef>> removedChildAssocs = this.editableNode.getRemovedChildAssociations();
        for (Map<String, ChildAssociationRef> typedAssoc : removedChildAssocs.values()) {
            for (ChildAssociationRef assoc : typedAssoc.values()) {
                getNodeService().removeChild(assoc.getParentRef(), assoc.getChildRef());
            }
        }
        // commit the transaction
        tx.commit();
        // set the outcome to refresh
        outcome = "finish";
        // reset the document held by the browse bean as it's just been updated
        this.browseBean.getDocument().reset();
    } catch (FileExistsException e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        // print status message
        String statusMsg = MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), "error_exists"), e.getName());
        Utils.addErrorMessage(statusMsg);
        // no outcome
        outcome = null;
    } catch (InvalidNodeRefException err) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() }));
        // this failure means the node no longer exists - we cannot show the doc properties screen
        outcome = "browse";
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
    }
    return outcome;
}
Also used : UserTransaction(javax.transaction.UserTransaction) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) HashMap(java.util.HashMap) Map(java.util.Map) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 69 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class AdminNodeBrowseBean method selectFromNode.

/**
 * Action to select association From node
 *
 * @return next action
 */
public String selectFromNode() {
    AssociationRef assocRef = (AssociationRef) getSourceAssocs().getRowData();
    NodeRef sourceRef = assocRef.getSourceRef();
    setNodeRef(sourceRef);
    return "success";
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 70 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class UIAssociationEditor method removeTarget.

/**
 * Updates the component and node state to reflect an association being removed
 *
 * @param node The node we are dealing with
 * @param targetRef The noderef of the child to remove
 */
protected void removeTarget(Node node, String targetRef) {
    if (node != null && targetRef != null) {
        QName assocQName = Repository.resolveToQName(this.associationName);
        AssociationRef newAssoc = new AssociationRef(null, node.getNodeRef(), assocQName, new NodeRef(targetRef));
        // was one of the original ones
        if (this.originalAssocs.containsKey(targetRef)) {
            Map<String, AssociationRef> removed = node.getRemovedAssociations().get(this.associationName);
            removed.put(targetRef, newAssoc);
            if (logger.isDebugEnabled())
                logger.debug("Added association to " + targetRef + " to the removed list");
        }
        // if this association was previously added in this session it will still be
        // in the added list so remove it if it is
        Map<String, AssociationRef> added = node.getAddedAssociations().get(this.associationName);
        if (added.containsKey(targetRef)) {
            added.remove(targetRef);
            if (logger.isDebugEnabled())
                logger.debug("Removed association to " + targetRef + " from the added list");
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Aggregations

AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)138 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)102 QName (org.alfresco.service.namespace.QName)56 ArrayList (java.util.ArrayList)44 Serializable (java.io.Serializable)30 Test (org.junit.Test)26 HashMap (java.util.HashMap)24 List (java.util.List)15 Pair (org.alfresco.util.Pair)14 HashSet (java.util.HashSet)13 Map (java.util.Map)13 StoreRef (org.alfresco.service.cmr.repository.StoreRef)12 BaseSpringTest (org.alfresco.util.BaseSpringTest)10 Extend (org.alfresco.traitextender.Extend)8 Iterator (java.util.Iterator)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Path (org.alfresco.service.cmr.repository.Path)6 Version (org.alfresco.service.cmr.version.Version)6