Java Code Examples for org.alfresco.service.namespace.QName#getLocalName()

The following examples show how to use org.alfresco.service.namespace.QName#getLocalName() . 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: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Pair<Long, QName> findByValue(QName qname)
{
    String uri = qname.getNamespaceURI();
    String localName = qname.getLocalName();
    Pair<Long, String> namespaceEntity = getNamespace(uri);
    if (namespaceEntity == null)
    {
        // There is no match on NS, so there is no QName like this
        return null;
    }
    Long nsId = namespaceEntity.getFirst();
    QNameEntity entity = findQNameEntityByNamespaceAndLocalName(nsId, localName);
    if (entity == null)
    {
        return null;
    }
    else
    {
        return new Pair<Long, QName>(entity.getId(), qname);
    }
}
 
Example 2
Source File: AssocTargetRoleIntegrityEvent.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Checks that the association name matches the constraints imposed by the model.
 */
protected void checkAssocQNameRegex(
        List<IntegrityRecord> eventResults,
        ChildAssociationDefinition assocDef,
        QName assocQName,
        NodeRef sourceNodeRef)
{
    // check the association name
    QName assocRoleQName = assocDef.getTargetRoleName();
    if (assocRoleQName != null)
    {
        // the assoc defines a role name - check it
        RegexQNamePattern rolePattern = new RegexQNamePattern(assocRoleQName.getNamespaceURI(), assocRoleQName.getLocalName());
        if (!rolePattern.isMatch(assocQName))
        {
            IntegrityRecord result = new IntegrityRecord(
                    "The association name does not match the allowed role names: \n" +
                    "   Source Node: " + sourceNodeRef + "\n" +
                    "   Association: " + assocDef + "\n" +
                    "   Allowed roles: " + rolePattern + "\n" +
                    "   Name assigned: " + assocRoleQName);
            eventResults.add(result);
        }
    }
}
 
Example 3
Source File: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public int updateValue(Long id, QName qname)
{ 
    String uri = qname.getNamespaceURI();
    String localName = qname.getLocalName();

    QNameEntity entity = findQNameEntityById(id);
    if (entity == null)
    {
        // No chance of updating
        return 0;
    }

    // Create namespace
    Pair<Long, String> namespaceEntity = getOrCreateNamespace(uri);
    Long nsId = namespaceEntity.getFirst();
    // Create QName
    return updateQNameEntity(entity, nsId, localName);
}
 
Example 4
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @return The array of aspects applied to this node as short prefix qname strings
 */
public Scriptable getAspectsShort()
{
    final NamespaceService ns = this.services.getNamespaceService();
    final Map<String, String> cache = new HashMap<String, String>();
    final Set<QName> aspects = getAspectsSet();
    final Object[] result = new Object[aspects.size()];
    int count = 0;
    for (final QName qname : aspects)
    {
        String prefix = cache.get(qname.getNamespaceURI());
        if (prefix == null)
        {
            // first request for this namespace prefix, get and cache result
            Collection<String> prefixes = ns.getPrefixes(qname.getNamespaceURI());
            prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
            cache.put(qname.getNamespaceURI(), prefix);
        }
        result[count++] = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName();
    }
    return Context.getCurrentContext().newArray(this.scope, result);
}
 
Example 5
Source File: PropertyFieldProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private PropertyFieldDefinition makePropertyFieldDefinition(final PropertyDefinition propDef, FieldGroup group)
{
    String name = getPrefixedName(propDef);
    QName dataType = propDef.getDataType().getName();
    PropertyFieldDefinition fieldDef = new PropertyFieldDefinition(name, dataType.getLocalName());
    
    populateFieldDefinition(propDef, fieldDef, group, PROP_DATA_PREFIX);

    fieldDef.setDefaultValue(propDef.getDefaultValue());
    fieldDef.setMandatory(propDef.isMandatory());
    fieldDef.setRepeating(propDef.isMultiValued());

    fieldDef.setIndexTokenisationMode(propDef.getIndexTokenisationMode());

    // any property from the system model (sys prefix) should be protected
    // the model doesn't
    // currently enforce this so make sure they are not editable
    if (NamespaceService.SYSTEM_MODEL_1_0_URI.equals(propDef.getName().getNamespaceURI()))
    {
        fieldDef.setProtectedField(true);
    }

    // If the property data type is d:period we need to setup a data
    // type parameters object to represent the options and rules
    if (dataType.equals(DataTypeDefinition.PERIOD))
    {
        PeriodDataTypeParameters periodOptions = getPeriodOptions();
        fieldDef.setDataTypeParameters(periodOptions);
    }

    // setup constraints for the property
    List<FieldConstraint> fieldConstraints = makeFieldConstraints(propDef);
    fieldDef.setConstraints(fieldConstraints);
    return fieldDef;
}
 
Example 6
Source File: AbstractQNameDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Pair<Long, QName> createValue(QName qname)
{
    String uri = qname.getNamespaceURI();
    String localName = qname.getLocalName();
    // Create namespace
    Pair<Long, String> namespaceEntity = getOrCreateNamespace(uri);
    Long nsId = namespaceEntity.getFirst();
    // Create QName
    QNameEntity entity = createQNameEntity(nsId, localName);
    return new Pair<Long, QName>(entity.getId(), qname);
}
 
Example 7
Source File: RenditionService2Impl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onContentUpdate(NodeRef sourceNodeRef, boolean newContent)
{
    if (isEnabled())
    {
        if (nodeService.exists(sourceNodeRef))
        {
            logger.debug("onContentUpdate on " + sourceNodeRef);
            List<ChildAssociationRef> childAssocs = getRenditionChildAssociations(sourceNodeRef);
            for (ChildAssociationRef childAssoc : childAssocs)
            {
                NodeRef renditionNodeRef = childAssoc.getChildRef();
                // TODO: This check will not be needed once the original RenditionService is removed.
                if (nodeService.hasAspect(renditionNodeRef, RenditionModel.ASPECT_RENDITION2))
                {
                    QName childAssocQName = childAssoc.getQName();
                    String renditionName = childAssocQName.getLocalName();
                    RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
                    if (renditionDefinition != null)
                    {
                        render(sourceNodeRef, renditionName);
                    }
                    else
                    {
                        logger.debug("onContentUpdate rendition " + renditionName + " only exists in the original rendition service.");
                    }
                }
            }
        }
        else
        {
            logger.debug("onContentUpdate rendition " + sourceNodeRef + " does not exist.");
        }
    }
}
 
Example 8
Source File: ChildAssocEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set all required fields associated with the patch <code>QName</code>.
 * 
 * @param forUpdate                 <tt>true</tt> if the entity is going to be used for a
 *                                  data update i.e. the <code>QName</code> <b>must</b> exist.
 * @return                          Returns <tt>true</tt> if the <code>QName</code> namespace
 *                                  exists.
 */
public boolean setQNameAll(QNameDAO qnameDAO, QName qname, boolean forUpdate)
{
    String assocQNameNamespace = qname.getNamespaceURI();
    String assocQNameLocalName = qname.getLocalName();
    Long assocQNameNamespaceId = null;
    if (forUpdate)
    {
        assocQNameNamespaceId = qnameDAO.getOrCreateNamespace(assocQNameNamespace).getFirst();
    }
    else
    {
        Pair<Long, String> nsPair = qnameDAO.getNamespace(assocQNameNamespace);
        if (nsPair == null)
        {
            // We can't set anything
            return false;
        }
        else
        {
            assocQNameNamespaceId = nsPair.getFirst();
        }
    }
    Long assocQNameCrc = getQNameCrc(qname);

    this.qnameNamespaceId = assocQNameNamespaceId;
    this.qnameLocalName = assocQNameLocalName;
    this.qnameCrc = assocQNameCrc;
    
    // All set correctly
    return true;
}
 
Example 9
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private QName materializeAssocQName(QName assocQName)
{
    // Version nodes have too long assocQNames so we try
    // to detect references with "material" protocols in order to
    // replace the assocQNames with material correspondents.
    try
    {
        String lName = assocQName.getLocalName();
        NodeRef nrAssocQName = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
                                           lName);
        if (Reference.fromNodeRef(nrAssocQName)!= null)
        {
            nrAssocQName = smartStore.materializeIfPossible(nrAssocQName);
            QName materialAssocQName = QName.createQName(assocQName.getNamespaceURI(),
                                                         nrAssocQName.getId());
            return materialAssocQName;
        }
        else
        {
            return assocQName;
        }
    }
    catch (VirtualizationException e)
    {
        // We assume it can not be put through the
        // isReference-virtualize-materialize.
        if (logger.isDebugEnabled())
        {
            logger.debug("Defaulting on materializeAssocQName due to error.",
                         e);
        }
        return assocQName;
    }
}
 
Example 10
Source File: RenditionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private RenditionDefinition2 getEquivalentRenditionDefinition2(RenditionDefinition rendDefn)
{
    QName renditionQName = rendDefn.getRenditionName();
    String renditionName = renditionQName.getLocalName();
    RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
    RenditionDefinition2 renditionDefinition2 = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
    RenditionDefinition2 equivalentRenditionDefinition2 = null;
    if (renditionDefinition2 != null)
    {
        String targetMimetype = (String) rendDefn.getParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE);
        String targetMimetype2 = renditionDefinition2.getTargetMimetype();
        equivalentRenditionDefinition2 = targetMimetype.equals(targetMimetype2) ? renditionDefinition2 : null;
    }
    return equivalentRenditionDefinition2;
}
 
Example 11
Source File: AbstractLockDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Split a lock's qualified name into the component parts using the '.' (period) as a
 * separator on the localname.  The namespace is preserved.  The provided qualified
 * name will always be the last component in the returned list. 
 * 
 * @param lockQName                 the lock name to split into it's higher-level paths
 * @return                          Returns the namespace ID along with the ordered localnames
 */
protected List<QName> splitLockQName(QName lockQName)
{
    String ns = lockQName.getNamespaceURI();
    String name = lockQName.getLocalName();
    
    StringTokenizer tokenizer = new StringTokenizer(name, ".");
    List<QName> ret = new ArrayList<QName>(tokenizer.countTokens());
    StringBuilder sb = new StringBuilder();
    // Fill it
    boolean first = true;
    while (tokenizer.hasMoreTokens())
    {
        if (first)
        {
            first = false;
        }
        else
        {
            sb.append(".");
        }
        sb.append(tokenizer.nextToken());
        QName parentLockQName = QName.createQName(ns, sb.toString());
        ret.add(parentLockQName);
    }
    // Done
    return ret;
}
 
Example 12
Source File: ActionNonParameterField.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActionNonParameterField(String name, QName type)
{
    this.name = name;
    this.fieldDef = new PropertyFieldDefinition(this.name, type.getLocalName());
    
    this.fieldDef.setLabel(this.name);
    this.fieldDef.setDataKeyName(this.name);
}
 
Example 13
Source File: ThumbnailServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Map<String, FailedThumbnailInfo> getFailedThumbnails(NodeRef sourceNode)
{
    Map<String, FailedThumbnailInfo> result = Collections.emptyMap();
    
    if (nodeService.hasAspect(sourceNode, ContentModel.ASPECT_FAILED_THUMBNAIL_SOURCE))
    {
        List<ChildAssociationRef> failedThumbnailChildren = nodeService.getChildAssocs(sourceNode,
                                             ContentModel.ASSOC_FAILED_THUMBNAIL, RegexQNamePattern.MATCH_ALL);
        result = new HashMap<String, FailedThumbnailInfo>();
        for (ChildAssociationRef chAssRef : failedThumbnailChildren)
        {
            final QName failedThumbnailName = chAssRef.getQName();
            NodeRef failedThumbnailNode = chAssRef.getChildRef();
            Map<QName, Serializable> props = nodeService.getProperties(failedThumbnailNode);
            Date failureDateTime = (Date)props.get(ContentModel.PROP_FAILED_THUMBNAIL_TIME);
            int failureCount = (Integer)props.get(ContentModel.PROP_FAILURE_COUNT);
            
            final FailedThumbnailInfo failedThumbnailInfo = new FailedThumbnailInfo(failedThumbnailName.getLocalName(),
                                                                            failureDateTime, failureCount,
                                                                            failedThumbnailNode);
            result.put(failedThumbnailName.getLocalName(), failedThumbnailInfo);
        }
    }
    else
    {
    	logger.debug(sourceNode + " does not have " + ContentModel.ASPECT_FAILED_THUMBNAIL_SOURCE + " aspect");
    }

    return result;
}
 
Example 14
Source File: PropertyValueSizeIsMoreMaxLengthException.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PropertyValueSizeIsMoreMaxLengthException(QName name)
{
    super("Property '" + name.getLocalName() + "' has size more than max value.");
}
 
Example 15
Source File: RepositoryNodeRefResolver.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public NodeRef createQNamePath(String[] reference, String[] names)
{
    Stack<String> notFoundStack = new Stack<>();
    Stack<String> notFoundNameStack = new Stack<>();
    NodeRef found;
    if (reference == null || reference.length == 0)
    {
        found = getRootHome();
    }
    else
    {
        NodeRef parentNodeRef = null;
        for (int i = reference.length; i > 0; i--)
        {
            String[] parent = new String[i];
            System.arraycopy(reference,
                             0,
                             parent,
                             0,
                             i);
            parentNodeRef = resolveQNameReference(parent);
            if (parentNodeRef != null)
            {
                break;
            }
            else
            {
                if (names != null)
                {
                    int offset = reference.length - i;
                    if (offset < names.length)
                    {
                        notFoundNameStack.push(names[names.length - 1 - offset]);
                    }
                }
                notFoundStack.push(reference[i - 1]);
            }
        }
        while (!notFoundStack.isEmpty())
        {
            String stringQNameToCreate = notFoundStack.pop();
            QName qNameToCreate = QName.createQName(stringQNameToCreate,
                                                    namespacePrefixResolver);
            String nameToCreate;
            if (!notFoundNameStack.isEmpty())
            {
                nameToCreate = notFoundNameStack.pop();
            }
            else
            {
                nameToCreate = qNameToCreate.getLocalName();
            }
            final HashMap<QName, Serializable> newProperties = new HashMap<QName, Serializable>();
            newProperties.put(ContentModel.PROP_NAME,
                              nameToCreate);
            ChildAssociationRef newAssoc = nodeService.createNode(parentNodeRef,
                                                                  ContentModel.ASSOC_CONTAINS,
                                                                  qNameToCreate,
                                                                  ContentModel.TYPE_FOLDER,
                                                                  newProperties);
            parentNodeRef = newAssoc.getChildRef();
        }

        found = parentNodeRef;
    }

    return found;

}
 
Example 16
Source File: AbstractLockDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Put new values against the given exclusive lock.  This works against the related locks as well.
 * @param optimistic                    <tt>true</tt> if a mismatch in the number of locked rows should
 *                                      be ignored.
 * @return                              <tt>true</tt> if the lock was successfully and fully updated
 *                                      using the lock token provided
 * @throws LockAcquisitionException     if the method is pessimistic and the number of rows does not
 *                                      correspond to the number expected
 */
private boolean updateLocks(
        QName lockQName,
        String lockToken,
        String newLockToken,
        long timeToLive,
        boolean optimistic)
{
    String qnameNamespaceUri = lockQName.getNamespaceURI();
    String qnameLocalName = lockQName.getLocalName();
    // Force lower case for case insensitivity
    if (!qnameLocalName.toLowerCase().equals(qnameLocalName))
    {
        lockQName = QName.createQName(qnameNamespaceUri, qnameLocalName.toLowerCase());
        qnameLocalName = lockQName.getLocalName();
    }
    // Force the lock token to lowercase
    lockToken = lockToken.toLowerCase();
    
    // Resolve the namespace
    Long qnameNamespaceId = qnameDAO.getOrCreateNamespace(qnameNamespaceUri).getFirst();
    
    // Get the lock resource for the exclusive lock.
    // All the locks that are created will need the exclusive case.
    LockResourceEntity exclusiveLockResource = getLockResource(qnameNamespaceId, qnameLocalName);
    if (exclusiveLockResource == null)
    {
        // If the exclusive lock doesn't exist, the locks don't exist
        throw new LockAcquisitionException(
                LockAcquisitionException.ERR_LOCK_RESOURCE_MISSING,
                lockQName, lockToken);
    }
    Long exclusiveLockResourceId = exclusiveLockResource.getId();
    // Split the lock name
    List<QName> lockQNames = splitLockQName(lockQName);
    // We just need to know how many resources needed updating.
    // They will all share the same exclusive lock resource
    int requiredUpdateCount = lockQNames.size();
    // Update
    int updateCount = updateLocks(exclusiveLockResourceId, lockToken, newLockToken, timeToLive);
    // Check
    if (updateCount != requiredUpdateCount)
    {
        if (optimistic)
        {
            // We don't mind.  Assume success but report that the lock was not removed by us.
            return false;
        }
        // Fall through to error states (pessimistic)
        if (LOCK_TOKEN_RELEASED.equals(newLockToken))
        {
            throw new LockAcquisitionException(
                    LockAcquisitionException.ERR_FAILED_TO_RELEASE_LOCK,
                    lockQName, lockToken);
        }
        else
        {
            throw new LockAcquisitionException(
                    LockAcquisitionException.ERR_LOCK_UPDATE_COUNT,
                    lockQName, lockToken, new Integer(updateCount), new Integer(requiredUpdateCount));
        }
    }
    else
    {
        // All updated successfully
        return true;
    }
    // Done
}
 
Example 17
Source File: XMLTransferRequsiteReader.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Start Element
 */
public void startElement(String uri, String localName, String prefixName, Attributes atts)
throws SAXException
{
    QName elementQName = QName.resolveToQName(this, prefixName);
    
    HashMap<String, String> namespace = new HashMap<String, String>();
    namespaces.addFirst(namespace);
            
    /**
     * Look for any namespace attributes
     */
    for(int i = 0; i < atts.getLength(); i++)
    {
        QName attributeQName = QName.resolveToQName(this, atts.getQName(i));
        if(attributeQName.getNamespaceURI().equals(XMLNS_URI))
        {
            namespace.put(attributeQName.getLocalName(), atts.getValue(i));
        }
    }
    
    if(elementQName == null)
    {
        return;
    }
    
    if(elementQName.getNamespaceURI().equals(REQUSITE_URI));
    {
        // This is one of the transfer manifest elements
        String elementName = elementQName.getLocalName();
        
        // Simple and stupid parser for now
        if(elementName.equals(RequsiteModel.LOCALNAME_TRANSFER_REQUSITE))
        {
            // Good we got this
        }
        else if(elementName.equals(RequsiteModel.LOCALNAME_ELEMENT_CONTENT))
        {
            NodeRef nodeRef = new NodeRef(atts.getValue("", "nodeRef"));
            QName qname = QName.createQName(atts.getValue("", "qname"));
            String name = atts.getValue("", "name");
            
            processor.missingContent(nodeRef, qname, name);
        }
    } // if transfer URI       
}
 
Example 18
Source File: CopyServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public NodeRef copy(
        NodeRef sourceNodeRef,
        NodeRef targetParentRef, 
        QName assocTypeQName,
        QName assocQName, 
        boolean copyChildren)
{
    // Check that all the passed values are not null
    ParameterCheck.mandatory("sourceNodeRef", sourceNodeRef);
    ParameterCheck.mandatory("targetParentRef", targetParentRef);
    ParameterCheck.mandatory("assocTypeQName", assocTypeQName);
    ParameterCheck.mandatory("assocQName", assocQName);

    if (sourceNodeRef.getStoreRef().equals(targetParentRef.getStoreRef()) == false)
    {
        // Error - since at the moment we do not support cross store copying
        throw new UnsupportedOperationException("Copying nodes across stores is not currently supported.");
    }

    // ALF-17549: Transform Action causes the Path QName to change to "'cm:copy''
    QName sourceNodeTypeQName = nodeService.getType(sourceNodeRef);

    if (dictionaryService.isSubClass(sourceNodeTypeQName, ContentModel.TYPE_CONTENT) || dictionaryService.isSubClass(sourceNodeTypeQName, ContentModel.TYPE_FOLDER))
    {
        String newName = assocQName.getLocalName();
        String currentName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(sourceNodeRef, ContentModel.PROP_NAME));
        assocQName = getAssociationCopyInfo(nodeService, sourceNodeRef, null, newName, !currentName.equals(newName)).getTargetAssocQName();
    }

    // Clear out any record of copied associations
    TransactionalResourceHelper.getList(KEY_POST_COPY_ASSOCS).clear();
    
    // Keep track of copied children in order of copying
    Map<NodeRef, NodeRef> copiesByOriginals = new LinkedHashMap<NodeRef, NodeRef>(17);
    Set<NodeRef> copies = new HashSet<NodeRef>(17);

    NodeRef copiedNodeRef = copyImpl(
            sourceNodeRef, targetParentRef,
            assocTypeQName, assocQName,
            copyChildren, true,                     // Drop cm:name for top-level node
            copiesByOriginals, copies);
    // Check if the node was copied
    if (copiedNodeRef == null)
    {
        CopyDetails copyDetails = getCopyDetails(sourceNodeRef, targetParentRef, null, assocTypeQName, assocQName);
        // Denied!
        throw new CopyServiceException(
                "A bound policy denied copy: \n" +
                "   " + copyDetails);
    }
    
    // Copy an associations that were left until now
    copyPendingAssociations(copiesByOriginals);
    
    // Foreach of the newly created copies call the copy complete policy
    for (Map.Entry<NodeRef, NodeRef> entry : copiesByOriginals.entrySet())
    {
        NodeRef mappedSourceNodeRef = entry.getKey();
        NodeRef mappedTargetNodeRef = entry.getValue();
        invokeCopyComplete(mappedSourceNodeRef, mappedTargetNodeRef, true, copiesByOriginals);
    }
    
    // Done
    return copiedNodeRef;
}
 
Example 19
Source File: VersionUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void convertFrozenToOriginalProps(Map<QName, Serializable> props) throws InvalidNodeRefException
{
    if (props != null)
    {
        props.remove(Version2Model.PROP_QNAME_VERSION_DESCRIPTION);
        props.remove(Version2Model.PROP_QNAME_VERSION_NUMBER);
        
        Set<QName> keys = new HashSet<QName>(props.keySet());
        for (QName key : keys)
        {
            String keyName = key.getLocalName();
            int idx = keyName.indexOf(Version2Model.PROP_METADATA_PREFIX);
            if (idx == 0)
            {
                props.remove(key);
            }
        }
        
        String versionLabel = (String)props.get(Version2Model.PROP_QNAME_VERSION_LABEL);
        props.put(ContentModel.PROP_VERSION_LABEL, versionLabel);
        props.remove(Version2Model.PROP_QNAME_VERSION_LABEL);
        
        // Convert frozen sys:referenceable properties
        NodeRef nodeRef = (NodeRef)props.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF);
        if (nodeRef != null)
        {
            props.put(ContentModel.PROP_STORE_PROTOCOL, nodeRef.getStoreRef().getProtocol());
            props.put(ContentModel.PROP_STORE_IDENTIFIER, nodeRef.getStoreRef().getIdentifier());
            props.put(ContentModel.PROP_NODE_UUID, nodeRef.getId());
        }
        props.remove(Version2Model.PROP_QNAME_FROZEN_NODE_REF);

        Long dbid = (Long)props.get(Version2Model.PROP_QNAME_FROZEN_NODE_DBID);
        props.put(ContentModel.PROP_NODE_DBID, dbid);
        props.remove(Version2Model.PROP_QNAME_FROZEN_NODE_DBID);
        
        // Convert frozen cm:auditable properties

        String creator = (String)props.get(Version2Model.PROP_QNAME_FROZEN_CREATOR);
        if (creator != null)
        {
            props.put(ContentModel.PROP_CREATOR, creator);
        }
        props.remove(Version2Model.PROP_QNAME_FROZEN_CREATOR);
        
        Date created = (Date)props.get(Version2Model.PROP_QNAME_FROZEN_CREATED);
        if (created != null)
        {
            props.put(ContentModel.PROP_CREATED, created);
        }
        props.remove(Version2Model.PROP_QNAME_FROZEN_CREATED);
        
        // TODO - check use-cases for get version, revert, restore ....
        String modifier = (String)props.get(Version2Model.PROP_QNAME_FROZEN_MODIFIER);
        if (modifier != null)
        {
            props.put(ContentModel.PROP_MODIFIER, modifier);
        }
        props.remove(Version2Model.PROP_QNAME_FROZEN_MODIFIER);
        
        Date modified = (Date)props.get(Version2Model.PROP_QNAME_FROZEN_MODIFIED);
        if (modified != null)
        {
            props.put(ContentModel.PROP_MODIFIED, modified);
        }
        props.remove(Version2Model.PROP_QNAME_FROZEN_MODIFIED);

        Date accessed = (Date)props.get(Version2Model.PROP_QNAME_FROZEN_ACCESSED);
        if (accessed != null)
        {
            props.put(ContentModel.PROP_ACCESSED, accessed);
        }
        props.remove(Version2Model.PROP_QNAME_FROZEN_ACCESSED);
    }
}
 
Example 20
Source File: ActionParameterField.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ActionParameterField(ParameterDefinition parameterDef, ActionService actionService)
{
    //TODO i18n
    
    this.name = parameterDef.getName();
    
    QName type = parameterDef.getType();
    final List<FieldConstraint> fieldConstraints = processActionConstraints(parameterDef, actionService);
    
    if (DataTypeDefinition.NODE_REF.equals(type) && fieldConstraints.isEmpty())
    {
        // Parameters of type NodeRef need to be AssociationPickers so that a NodeRef can be selected in the form
        // using the association picker for navigation.
        // However this is only true for NodeRef parameters without constraints.
        // NodeRef parameters which are constrained (to a list of particular NodeRefs) will
        // be handled below.
        this.fieldDef = new AssociationFieldDefinition(this.name, "cm:cmobject", AssociationFieldDefinition.Direction.TARGET);
        AssociationFieldDefinition assocFieldDef = (AssociationFieldDefinition) this.fieldDef;
        assocFieldDef.setEndpointMandatory(parameterDef.isMandatory());
        assocFieldDef.setEndpointMany(parameterDef.isMultiValued());
    }
    else
    {
        if (DataTypeDefinition.NODE_REF.equals(type))
        {
            // constrained NodeRef parameter (assumed list of particular NodeRefs)
            this.fieldDef = new PropertyFieldDefinition(this.name, DataTypeDefinition.TEXT.getLocalName());
        }
        else
        {    
            this.fieldDef = new PropertyFieldDefinition(this.name, type.getLocalName());
        }
        PropertyFieldDefinition propFieldDef = (PropertyFieldDefinition)this.fieldDef;
        
        
        propFieldDef.setMandatory(parameterDef.isMandatory());
        propFieldDef.setRepeating(parameterDef.isMultiValued());
        
        if (!fieldConstraints.isEmpty())
        {
            propFieldDef.setConstraints(fieldConstraints);
        }
    }
    
    // Properties common to PropertyFieldDefinitions and AssociationFieldDefinitions.
    this.fieldDef.setDescription(parameterDef.getName());
    this.fieldDef.setLabel(parameterDef.getDisplayLabel());
    this.fieldDef.setDataKeyName(this.name);
}