org.apache.chemistry.opencmis.commons.data.PropertyData Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.data.PropertyData. 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: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the value of the given property if it exists and is of the
 * correct type.
 */
public String getIdProperty(Properties properties, String propertyId)
{
    if ((properties == null) || (properties.getProperties() == null))
    {
        return null;
    }

    PropertyData<?> property = properties.getProperties().get(propertyId);
    if (!(property instanceof PropertyId))
    {
        return null;
    }

    return ((PropertyId) property).getFirstValue();
}
 
Example #2
Source File: FavouriteDocument.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static FavouriteDocument getDocument(String id, String guid, Properties props)
{
    FavouriteDocument document = new FavouriteDocument(id, guid);

    Map<String, PropertyData<?>> properties = props.getProperties();
    document.setName((String)properties.get(PropertyIds.NAME).getFirstValue());
    document.setTitle((String)properties.get(ContentModel.PROP_TITLE.toString()).getFirstValue());
    document.setCreatedBy((String)properties.get(PropertyIds.CREATED_BY).getFirstValue());
    document.setModifiedBy((String)properties.get(PropertyIds.LAST_MODIFIED_BY).getFirstValue());
    GregorianCalendar modifiedAt = (GregorianCalendar)properties.get(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    document.setModifiedAt(modifiedAt.getTime());
    GregorianCalendar createdAt = (GregorianCalendar)properties.get(PropertyIds.CREATION_DATE).getFirstValue();
    document.setCreatedAt(createdAt.getTime());
    //document.setDescription((String)props.get(PropertyIds.DE).getFirstValue());
    document.setMimeType((String)properties.get(PropertyIds.CONTENT_STREAM_MIME_TYPE).getFirstValue());
    document.setSizeInBytes((BigInteger)properties.get(PropertyIds.CONTENT_STREAM_LENGTH).getFirstValue());
    document.setVersionLabel((String)properties.get(PropertyIds.VERSION_LABEL).getFirstValue());
    return document;
}
 
Example #3
Source File: IbisObjectService.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProperties(String repositoryId, Holder<String> objectId,
		Holder<String> changeToken, Properties properties,
		ExtensionsData extension) {

	if(!eventDispatcher.contains(CmisEvent.UPDATE_PROPERTIES)) {
		objectService.updateProperties(repositoryId, objectId, changeToken, properties, extension);
	}
	else {
		XmlBuilder cmisXml = new XmlBuilder("cmis");
		cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
		if(objectId != null)
			cmisXml.addSubElement(buildXml("objectId", objectId.getValue()));
		if(changeToken != null)
			cmisXml.addSubElement(buildXml("changeToken", changeToken.getValue()));

		XmlBuilder propertiesXml = new XmlBuilder("properties");
		for (Iterator<PropertyData<?>> it = properties.getPropertyList().iterator(); it.hasNext();) {
			propertiesXml.addSubElement(CmisUtils.getPropertyXml(it.next()));
		}
		cmisXml.addSubElement(propertiesXml);

		eventDispatcher.trigger(CmisEvent.UPDATE_PROPERTIES, cmisXml.toXML(), callContext);
	}
}
 
Example #4
Source File: Converter.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a properties object
 * 
 * @param properties the properties
 * 
 * @return the conversion
 */
public static CmisPropertiesType convert(Properties properties) {
	if (properties == null) {
		return null;
	}

	CmisPropertiesType result = new CmisPropertiesType();

	if (properties.getProperties() != null) {
		for (PropertyData<?> property : properties.getProperties().values()) {
			result.getProperty().add(convert(property));
		}
	}

	// handle extensions
	convertExtension(properties, result);

	return result;
}
 
Example #5
Source File: FavouriteFolder.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static FavouriteFolder getFolder(String id, String guid, Properties props)
{
    FavouriteFolder folder = new FavouriteFolder(id, guid);

    Map<String, PropertyData<?>> properties = props.getProperties();
    folder.setName((String)properties.get(PropertyIds.NAME).getFirstValue());
    folder.setTitle((String)properties.get(ContentModel.PROP_TITLE.toString()).getFirstValue());
    folder.setCreatedBy((String)properties.get(PropertyIds.CREATED_BY).getFirstValue());
    folder.setModifiedBy((String)properties.get(PropertyIds.LAST_MODIFIED_BY).getFirstValue());
    GregorianCalendar modifiedAt = (GregorianCalendar)properties.get(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
    folder.setModifiedAt(modifiedAt.getTime());
    GregorianCalendar createdAt = (GregorianCalendar)properties.get(PropertyIds.CREATION_DATE).getFirstValue();
    folder.setCreatedAt(createdAt.getTime());
    //document.setDescription((String)props.get(PropertyIds.DE).getFirstValue());
    return folder;
}
 
Example #6
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private PropertyData<?> getPropIsLatestMajorVersion(ObjectData objectData)
{
    List<PropertyData<?>> properties = objectData.getProperties().getPropertyList();
    boolean found = false;
    PropertyData<?> propIsLatestMajorVersion = null;
    for (PropertyData<?> property : properties)
    {
        if (property.getId().equals(PropertyIds.IS_LATEST_MAJOR_VERSION))
        {
            found = true;
            propIsLatestMajorVersion = property;
            break;
        }
    }
    //properties..contains(PropertyIds.IS_LATEST_MAJOR_VERSION);
    assertTrue("The PropertyIds.IS_LATEST_MAJOR_VERSION property was not found", found);
    if (found)
    {
        return propIsLatestMajorVersion;
    }
    
    return null;
}
 
Example #7
Source File: ConformanceCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Throws an exception if the given property isn't set or of the wrong type.
 */
protected void checkProperty(Properties properties, String propertyId, Class<?> clazz) {
    if (properties.getProperties() == null) {
        throw new CmisInvalidArgumentException("Property " + propertyId + " must be set!");
    }

    PropertyData<?> property = properties.getProperties().get(propertyId);
    if (property == null) {
        throw new CmisInvalidArgumentException("Property " + propertyId + " must be set!");
    }

    Object value = property.getFirstValue();
    if (value == null) {
        throw new CmisInvalidArgumentException("Property " + propertyId + " must have a value!");
    }

    if (!clazz.isAssignableFrom(value.getClass())) {
        throw new CmisInvalidArgumentException("Property " + propertyId + " has the wrong type!");
    }
}
 
Example #8
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the value of the given property if it exists and is of the
 * correct type.
 */
public String getStringProperty(Properties properties, String propertyId)
{
    if ((properties == null) || (properties.getProperties() == null))
    {
        return null;
    }

    PropertyData<?> property = properties.getProperties().get(propertyId);
    if (!(property instanceof PropertyString))
    {
        return null;
    }

    return ((PropertyString) property).getFirstValue();
}
 
Example #9
Source File: CmisPropertySetter.java    From spring-content with Apache License 2.0 6 votes vote down vote up
public void populate(Object bean) {

		if (properties == null) {
			return;
		}

		BeanWrapper wrapper = new BeanWrapperImpl(bean);

		Map<String, PropertyData<?>> props = properties.getProperties();
		for (String name : props.keySet()) {

			if ("cmis:objectTypeId".equals(name)) {
				continue;
			}

			Field[] fields = null;
			switch (name) {
				case "cmis:name":
					setCmisProperty(CmisName.class, wrapper, props.get(name).getValues());
					break;
				case "cmis:description":
					setCmisProperty(CmisDescription.class, wrapper, props.get(name).getValues());
					break;
			}
		}
	}
 
Example #10
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Properties getAssocProperties(CMISNodeInfo info, String filter)
{
    PropertiesImpl result = new PropertiesImpl();

    Set<String> filterSet = splitFilter(filter);

    for (PropertyDefinitionWrapper propDefWrap : info.getType().getProperties())
    {
        PropertyDefinition<?> propDef = propDefWrap.getPropertyDefinition();
        if ((filterSet != null) && (!filterSet.contains(propDef.getQueryName())))
        {
            // skip properties that are not in the filter
            continue;
        }

        CMISPropertyAccessor cmisPropertyAccessor = propDefWrap.getPropertyAccessor();
        Serializable value = cmisPropertyAccessor.getValue(info);
        PropertyType propType = propDef.getPropertyType();
        PropertyData<?> propertyData = getProperty(propType, propDefWrap, value);
        result.addProperty(propertyData);
    }

    return result;
}
 
Example #11
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the first value of an string property.
 */
private static String getStringProperty(Properties properties, String name) {

	PropertyData<?> property = properties.getProperties().get(name);

	if (property == null) {
		return null;
	}
	if (property instanceof PropertyId) {
		return ((PropertyId) property).getFirstValue();
	}
	if (!(property instanceof PropertyString)) {
		return null;
	}

	return ((PropertyString) property).getFirstValue();
}
 
Example #12
Source File: IbisObjectService.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public String createItem(String repositoryId, Properties properties,
		String folderId, List<String> policies, Acl addAces,
		Acl removeAces, ExtensionsData extension) {

	if(!eventDispatcher.contains(CmisEvent.CREATE_ITEM)) {
		return objectService.createItem(repositoryId, properties, folderId, policies, addAces, removeAces, extension);
	}
	else {
		XmlBuilder cmisXml = new XmlBuilder("cmis");
		cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
		cmisXml.addSubElement(buildXml("folderId", folderId));
		cmisXml.addSubElement(buildXml("policies", policies));

		XmlBuilder propertiesXml = new XmlBuilder("properties");
		for (Iterator<PropertyData<?>> it = properties.getPropertyList().iterator(); it.hasNext();) {
			propertiesXml.addSubElement(CmisUtils.getPropertyXml(it.next()));
		}
		cmisXml.addSubElement(propertiesXml);

		Element result = eventDispatcher.trigger(CmisEvent.CREATE_ITEM, cmisXml.toXML(), callContext);
		return XmlUtils.getChildTagAsString(result, "id");
	}
}
 
Example #13
Source File: IbisObjectService.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public String createFolder(String repositoryId, Properties properties,
		String folderId, List<String> policies, Acl addAces,
		Acl removeAces, ExtensionsData extension) {

	if(!eventDispatcher.contains(CmisEvent.CREATE_FOLDER)) {
		return objectService.createFolder(repositoryId, properties, folderId, policies, addAces, removeAces, extension);
	}
	else {
		XmlBuilder cmisXml = new XmlBuilder("cmis");
		cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
		cmisXml.addSubElement(buildXml("folderId", folderId));
		cmisXml.addSubElement(buildXml("policies", policies));

		XmlBuilder propertiesXml = new XmlBuilder("properties");
		for (Iterator<PropertyData<?>> it = properties.getPropertyList().iterator(); it.hasNext();) {
			propertiesXml.addSubElement(CmisUtils.getPropertyXml(it.next()));
		}
		cmisXml.addSubElement(propertiesXml);

		Element result = eventDispatcher.trigger(CmisEvent.CREATE_FOLDER, cmisXml.toXML(), callContext);
		return XmlUtils.getChildTagAsString(result, "id");
	}
}
 
Example #14
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void assertVersions(final NodeRef nodeRef, final String expectedVersionLabel, final VersionType expectedVersionType)
{
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>()
    {
        @Override
        public List<Void> execute() throws Throwable
        {
            assertTrue("Node should be versionable", nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE));
            
            Version version = versionService.getCurrentVersion(nodeRef);
            
            assertNotNull(version);
            assertEquals(expectedVersionLabel, version.getVersionLabel());
            assertEquals(expectedVersionType, version.getVersionType());
            
            return null;
        }
    });
    
    withCmisService(new CmisServiceCallback<Void>()
    {
        @Override
        public Void execute(CmisService cmisService)
        {
            String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
            
            ObjectData data = 
                cmisService.getObjectOfLatestVersion(repositoryId, nodeRef.toString(), null, Boolean.FALSE, null, null, null, null, null, null, null);
            
            assertNotNull(data);
            
            PropertyData<?> prop = data.getProperties().getProperties().get(PropertyIds.VERSION_LABEL);
            Object versionLabelCmisValue = prop.getValues().get(0);
            
            assertEquals(expectedVersionLabel, versionLabelCmisValue);
            
            return null;
        }
    }, CmisVersion.CMIS_1_1);
}
 
Example #15
Source File: CMISNode.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CMISNode createNode(QueryResult qr)
{
	List<PropertyData<?>> props = qr.getProperties();
	Map<String, Serializable> properties = new HashMap<String, Serializable>();

	for(PropertyData<?> p : props)
	{
		properties.put(p.getId(), (Serializable)p.getFirstValue());
	}

	String objectId = (String)qr.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue();
	CMISNode n = new CMISNode(objectId, objectId, properties);
	return n;
}
 
Example #16
Source File: IbisObjectService.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public String createDocument(String repositoryId, Properties properties,
		String folderId, ContentStream contentStream,
		VersioningState versioningState, List<String> policies,
		Acl addAces, Acl removeAces, ExtensionsData extension) {

	if(!eventDispatcher.contains(CmisEvent.CREATE_DOCUMENT)) {
		return objectService.createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, addAces, removeAces, extension);
	}
	else {
		XmlBuilder cmisXml = new XmlBuilder("cmis");
		cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
		cmisXml.addSubElement(buildXml("folderId", folderId));
		cmisXml.addSubElement(buildXml("versioningState", versioningState));

		XmlBuilder contentStreamXml = new XmlBuilder("contentStream");
		contentStreamXml.addAttribute("filename", contentStream.getFileName());
		contentStreamXml.addAttribute("length", contentStream.getLength());
		contentStreamXml.addAttribute("mimeType", contentStream.getMimeType());
		cmisXml.addSubElement(contentStreamXml);

		XmlBuilder propertiesXml = new XmlBuilder("properties");
		for (Iterator<PropertyData<?>> it = properties.getPropertyList().iterator(); it.hasNext();) {
			propertiesXml.addSubElement(CmisUtils.getPropertyXml(it.next()));
		}
		cmisXml.addSubElement(propertiesXml);

		IPipeLineSession context = new PipeLineSessionBase();
		context.put("ContentStream", contentStream.getStream());
		context.put(CmisUtils.CMIS_CALLCONTEXT_KEY, callContext);
		Element result = eventDispatcher.trigger(CmisEvent.CREATE_DOCUMENT, cmisXml.toXML(), context);
		return XmlUtils.getChildTagAsString(result, "id");
	}
}
 
Example #17
Source File: CMISNode.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Map<String, Serializable> getProperties(Properties properties)
{
	Map<String, Serializable> propertiesMap = new HashMap<String, Serializable>();
	for(PropertyData<?> p : properties.getPropertyList())
	{
		propertiesMap.put(p.getId(), p.getFirstValue().toString());
	}
	return propertiesMap;
}
 
Example #18
Source File: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Properties getProperties(NodeRef nodeRef)
  {
CMISNodeInfoImpl nodeInfo = cmisConnector.createNodeInfo(nodeRef);
final Properties properties = cmisConnector.getNodeProperties(nodeInfo, null);
// fake the title property, which CMIS doesn't give us
String title = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
final PropertyStringImpl titleProp = new PropertyStringImpl(ContentModel.PROP_TITLE.toString(), title);
Properties wrapProperties = new Properties()
{
	@Override
	public List<CmisExtensionElement> getExtensions()
	{
		return properties.getExtensions();
	}

	@Override
	public void setExtensions(List<CmisExtensionElement> extensions)
	{
		properties.setExtensions(extensions);
	}

	@Override
	public Map<String, PropertyData<?>> getProperties()
	{
		Map<String, PropertyData<?>> updatedProperties = new HashMap<String, PropertyData<?>>(properties.getProperties());
		updatedProperties.put(titleProp.getId(), titleProp);
		return updatedProperties;
	}

	@Override
	public List<PropertyData<?>> getPropertyList()
	{
		List<PropertyData<?>> propertyList = new ArrayList<PropertyData<?>>(properties.getPropertyList());
		propertyList.add(titleProp);
		return propertyList;
	}
};
return wrapProperties;
  }
 
Example #19
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setProperiesToObject(CmisService cmisService, String repositoryId, String objectIdStr, String propertyStr, BigInteger bigIntValue) throws CmisConstraintException{
    Properties properties = cmisService.getProperties(repositoryId, objectIdStr, null, null);
    PropertyIntegerImpl pd = (PropertyIntegerImpl)properties.getProperties().get(propertyStr);
    pd.setValue(bigIntValue);
    
    Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
    propsList.add(pd);
    
    Properties newProps = new PropertiesImpl(propsList);
    
    cmisService.updateProperties(repositoryId, new Holder<String>(objectIdStr), null, newProps, null);
}
 
Example #20
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Serializable getValue(PropertyData<?> property, boolean isMultiValue)
{
    if ((property.getValues() == null) || (property.getValues().isEmpty()))
    {
        return null;
    }

    if (isMultiValue)
    {
        return (Serializable) property.getValues();
    }

    return (Serializable) property.getValues().get(0);
}
 
Example #21
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the type id from a set of properties.
 */
private static String getTypeId(Properties properties) {
	PropertyData<?> typeProperty = properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID);
	if (!(typeProperty instanceof PropertyId)) {
		throw new CmisInvalidArgumentException("Type id must be set!");
	}

	String typeId = ((PropertyId) typeProperty).getFirstValue();
	if (typeId == null) {
		throw new CmisInvalidArgumentException("Type id must be set!");
	}

	return typeId;
}
 
Example #22
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean isEmptyProperty(PropertyData<?> prop) {
	if ((prop == null) || (prop.getValues() == null)) {
		return true;
	}

	return prop.getValues().isEmpty();
}
 
Example #23
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test to ensure that versioning properties have default values defined in Alfresco content model.
 * Testing  <b>cm:initialVersion</b>, <b>cm:autoVersion</b> and <b>cm:autoVersionOnUpdateProps</b> properties 
 * 
 * @throws Exception
 */
@Test
public void testVersioningPropertiesHaveDefaultValue() throws Exception
{
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    try
    {
        // Create document via CMIS
        final NodeRef documentNodeRef = withCmisService(new CmisServiceCallback<NodeRef>()
        {
            @Override
            public NodeRef execute(CmisService cmisService)
            {
                String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();

                String rootNodeId = cmisService.getObjectByPath(repositoryId, "/", null, true, IncludeRelationships.NONE, null, false, true, null).getId();

                Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
                propsList.add(new PropertyStringImpl(PropertyIds.NAME, "Folder-" + GUID.generate()));
                propsList.add(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"));

                String folderId = cmisService.createFolder(repositoryId, new PropertiesImpl(propsList), rootNodeId, null, null, null, null);

                propsList = new ArrayList<PropertyData<?>>();
                propsList.add(new PropertyStringImpl(PropertyIds.NAME, "File-" + GUID.generate()));
                propsList.add(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:document"));

                String nodeId = cmisService.createDocument(repositoryId, new PropertiesImpl(propsList), folderId, null, null, null, null, null, null);

                return new NodeRef(nodeId.substring(0, nodeId.indexOf(';')));
            }
        }, CmisVersion.CMIS_1_1);

        // check versioning properties
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<Void>>()
        {
            @Override
            public List<Void> execute() throws Throwable
            {
                assertTrue(nodeService.exists(documentNodeRef));
                assertTrue(nodeService.hasAspect(documentNodeRef, ContentModel.ASPECT_VERSIONABLE));

                AspectDefinition ad = dictionaryService.getAspect(ContentModel.ASPECT_VERSIONABLE);
                Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> properties = ad.getProperties();

                for (QName qName : new QName[] {ContentModel.PROP_INITIAL_VERSION, ContentModel.PROP_AUTO_VERSION, ContentModel.PROP_AUTO_VERSION_PROPS})
                {
                    Serializable property = nodeService.getProperty(documentNodeRef, qName);

                    assertNotNull(property);

                    org.alfresco.service.cmr.dictionary.PropertyDefinition pd = properties.get(qName);
                    assertNotNull(pd.getDefaultValue());

                    assertEquals(property, Boolean.parseBoolean(pd.getDefaultValue()));
                }

                return null;
            }
        });
    }
    finally
    {
        AuthenticationUtil.popAuthentication();
    }
}
 
Example #24
Source File: CmisSender.java    From iaf with Apache License 2.0 4 votes vote down vote up
private String sendMessageForActionFind(String message) throws SenderException, TimeOutException {
	Element queryElement = null;
	try {
		if (XmlUtils.isWellFormed(message, "query")) {
			queryElement = XmlUtils.buildElement(message);
		} else {
			queryElement = XmlUtils.buildElement("<query/>");
		}
	} catch (DomBuilderException e) {
		throw new SenderException(e);
	}
	String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
	String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
	String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
	String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");

	String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");

	OperationContext operationContext = cmisSession.createOperationContext();
	if (StringUtils.isNotEmpty(maxItems)) {
		operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
	}
	boolean sav = false;
	if (StringUtils.isNotEmpty(searchAllVersions)) {
		sav = Boolean.parseBoolean(searchAllVersions);
	}
	if (StringUtils.isNotEmpty(includeAllowableActions)) {
		operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
	}

	XmlBuilder cmisXml = new XmlBuilder("cmis");
	ItemIterable<QueryResult> q = cmisSession.query(statement, sav, operationContext);

	if(q == null) {
		cmisXml.addAttribute("totalNumItems", 0);
	} else {
		if (StringUtils.isNotEmpty(skipCount)) {
			long sc = Long.parseLong(skipCount);
			q = q.skipTo(sc);
		}
		if (StringUtils.isNotEmpty(maxItems)) {
			q = q.getPage();
		}
		XmlBuilder rowsetXml = new XmlBuilder("rowset");
		for (QueryResult qResult : q) {
			XmlBuilder rowXml = new XmlBuilder("row");
			for (PropertyData<?> property : qResult.getProperties()) {
				rowXml.addSubElement(CmisUtils.getPropertyXml(property));
			}
			rowsetXml.addSubElement(rowXml);
		}
		cmisXml.addAttribute("totalNumItems", q.getTotalNumItems());
		cmisXml.addSubElement(rowsetXml);
	}
	return cmisXml.toXML();
}
 
Example #25
Source File: CmisUtils.java    From iaf with Apache License 2.0 4 votes vote down vote up
/**
 * @param object to translate to xml
 * @param cmisXml root XML element (defaults to creating a new 'objectData' element)
 * @return the root XML element
 */
public static XmlBuilder objectData2Xml(ObjectData object, XmlBuilder cmisXml) {

	if(object.getProperties() != null) {
		XmlBuilder propertiesXml = new XmlBuilder("properties");
		for (Iterator<PropertyData<?>> it = object.getProperties().getPropertyList().iterator(); it.hasNext();) {
			propertiesXml.addSubElement(CmisUtils.getPropertyXml(it.next()));
		}
		cmisXml.addSubElement(propertiesXml);
	}

	if(object.getAllowableActions() != null) {
		XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
		Set<Action> actions = object.getAllowableActions().getAllowableActions();
		for (Action action : actions) {
			XmlBuilder actionXml = new XmlBuilder("action");
			actionXml.setValue(action.value());
			allowableActionsXml.addSubElement(actionXml);
		}
		cmisXml.addSubElement(allowableActionsXml);
	}

	if(object.getAcl() != null) {
		XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
		isExactAclXml.setValue(object.getAcl().isExact().toString());
		cmisXml.addSubElement(isExactAclXml);
	}

	cmisXml.addAttribute("id", object.getId());
	if(object.getBaseTypeId() != null)
		cmisXml.addAttribute("baseTypeId", object.getBaseTypeId().name());

	PolicyIdList policies = object.getPolicyIds();
	if(policies != null) {
		XmlBuilder policiesXml = new XmlBuilder("policyIds");
		for (String objectId : policies.getPolicyIds()) {
			XmlBuilder policyXml = new XmlBuilder("policyId");
			policyXml.setValue(objectId);
			policiesXml.addSubElement(policyXml);
		}
		cmisXml.addSubElement(policiesXml);
	}

	XmlBuilder relationshipsXml = new XmlBuilder("relationships");
	List<ObjectData> relationships = object.getRelationships();
	if(relationships != null) {
		for (ObjectData relation : relationships) {
			relationshipsXml.addSubElement(objectData2Xml(relation, new XmlBuilder("relation")));
		}
	}
	cmisXml.addSubElement(relationshipsXml);

	return cmisXml;
}
 
Example #26
Source File: Node.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected Object getValue(Map<String, PropertyData<?>> props, String name)
{
    PropertyData<?> prop = props.get(name);
    Object value = (prop != null ? prop.getFirstValue() : null);
    return value;
}
 
Example #27
Source File: Converter.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Converts a property object
 * 
 * @param property the property
 * 
 * @return the conversion
 */
public static CmisProperty convert(PropertyData<?> property) {
	if (property == null) {
		return null;
	}

	CmisProperty result = null;

	if (property instanceof PropertyString) {
		result = new CmisPropertyString();
		((CmisPropertyString) result).getValue().addAll(((PropertyString) property).getValues());
	} else if (property instanceof PropertyId) {
		result = new CmisPropertyId();
		((CmisPropertyId) result).getValue().addAll(((PropertyId) property).getValues());
	} else if (property instanceof PropertyInteger) {
		result = new CmisPropertyInteger();
		((CmisPropertyInteger) result).getValue().addAll(((PropertyInteger) property).getValues());
	} else if (property instanceof PropertyDecimal) {
		result = new CmisPropertyDecimal();
		((CmisPropertyDecimal) result).getValue().addAll(((PropertyDecimal) property).getValues());
	} else if (property instanceof PropertyBoolean) {
		result = new CmisPropertyBoolean();
		((CmisPropertyBoolean) result).getValue().addAll(((PropertyBoolean) property).getValues());
	} else if (property instanceof PropertyDateTime) {
		result = new CmisPropertyDateTime();
		((CmisPropertyDateTime) result).getValue()
				.addAll(convertCalendar(((PropertyDateTime) property).getValues()));
	} else if (property instanceof PropertyHtml) {
		result = new CmisPropertyHtml();
		((CmisPropertyHtml) result).getValue().addAll(((PropertyHtml) property).getValues());
	} else if (property instanceof PropertyUri) {
		result = new CmisPropertyUri();
		((CmisPropertyUri) result).getValue().addAll(((PropertyUri) property).getValues());
	} else {
		return null;
	}

	result.setPropertyDefinitionId(property.getId());
	result.setLocalName(property.getLocalName());
	result.setQueryName(property.getQueryName());
	result.setDisplayName(property.getDisplayName());

	return result;
}