org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl. 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
public Properties getNodeProperties(CMISNodeInfo info, String filter)
{
    PropertiesImpl result = new PropertiesImpl();

    Set<String> filterSet = splitFilter(filter);

    for (PropertyDefinitionWrapper propDef : info.getType().getProperties())
    {
        if (!propDef.getPropertyId().equals(PropertyIds.OBJECT_ID))
        {
            // don't filter the object id
            if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName())))
            {
                // skip properties that are not in the filter
                continue;
            }
        }

        Serializable value = propDef.getPropertyAccessor().getValue(info);
        result.addProperty(getProperty(propDef.getPropertyDefinition().getPropertyType(), propDef, value));
    }

    addAspectProperties(info, filter, result);

    return result;
}
 
Example #2
Source File: IbisObjectService.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public Properties getProperties(String repositoryId, String objectId, String filter, ExtensionsData extension) {

	if(!eventDispatcher.contains(CmisEvent.GET_PROPERTIES)) {
		return objectService.getProperties(repositoryId, objectId, filter, extension);
	}
	else {
		XmlBuilder cmisXml = new XmlBuilder("cmis");
		cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
		cmisXml.addSubElement(buildXml("objectId", objectId));
		cmisXml.addSubElement(buildXml("filter", filter));
		try {

			Element result = eventDispatcher.trigger(CmisEvent.GET_PROPERTIES, cmisXml.toXML(), callContext);

			return CmisUtils.processProperties(result);
		}
		catch(Exception e) {
			log.error("error creating CMIS objectData: " + e.getMessage(), e.getCause());
		}
		return new PropertiesImpl();
	}
}
 
Example #3
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 #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 object to convert
 * 
 * @return the converted properties object
 */
public static Properties convert(CmisPropertiesType properties) {
	if (properties == null) {
		return null;
	}

	PropertiesImpl result = new PropertiesImpl();

	for (CmisProperty property : properties.getProperty()) {
		result.addProperty(convert(property));
	}

	// handle extensions
	convertExtension(properties, result);

	return result;
}
 
Example #5
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addPropertyBigInteger(PropertiesImpl props, String typeId, Set<String> filter, String id,
		BigInteger value) {
	if (!checkAddProperty(props, typeId, filter, id)) {
		return;
	}

	PropertyIntegerImpl p = new PropertyIntegerImpl(id, value);
	p.setQueryName(id);
	props.addProperty(p);
}
 
Example #6
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addPropertyId(PropertiesImpl props, String typeId, Set<String> filter, String id, String value) {
	if (!checkAddProperty(props, typeId, filter, id)) {
		return;
	}

	PropertyIdImpl p = new PropertyIdImpl(id, value);
	p.setQueryName(id);
	props.addProperty(p);
}
 
Example #7
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 5 votes vote down vote up
static void addPropertyDateTime(PropertiesImpl props, TypeDefinition type, Set<String> filter, String id, GregorianCalendar value) {
	if (!checkAddProperty(props, type, filter, id)) {
		return;
	}

	props.addProperty(new PropertyDateTimeImpl(id, value));
}
 
Example #8
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 5 votes vote down vote up
static void addPropertyBoolean(PropertiesImpl props, TypeDefinition type, Set<String> filter, String id, boolean value) {
	if (!checkAddProperty(props, type, filter, id)) {
		return;
	}

	props.addProperty(new PropertyBooleanImpl(id, value));
}
 
Example #9
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 5 votes vote down vote up
static void addPropertyBigInteger(PropertiesImpl props, TypeDefinition type, Set<String> filter, String id, BigInteger value) {
	if (!checkAddProperty(props, type, filter, id)) {
		return;
	}

	props.addProperty(new PropertyIntegerImpl(id, value));
}
 
Example #10
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 5 votes vote down vote up
static void addPropertyString(PropertiesImpl props, TypeDefinition type, Set<String> filter, String id, String value) {
	if (!checkAddProperty(props, type, filter, id)) {
		return;
	}

	props.addProperty(new PropertyStringImpl(id, value));
}
 
Example #11
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 5 votes vote down vote up
static void addPropertyId(PropertiesImpl props, TypeDefinition type, Set<String> filter, String id, String value) {
	if (!checkAddProperty(props, type, filter, id)) {
		return;
	}

	props.addProperty(new PropertyIdImpl(id, value));
}
 
Example #12
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 #13
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addPropertyIdList(PropertiesImpl props, String typeId, Set<String> filter, String id,
		List<String> value) {
	if (!checkAddProperty(props, typeId, filter, id)) {
		return;
	}

	PropertyIdImpl p = new PropertyIdImpl(id, value);
	p.setQueryName(id);
	props.addProperty(p);
}
 
Example #14
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addPropertyString(PropertiesImpl props, String typeId, Set<String> filter, String id, String value) {
	if (!checkAddProperty(props, typeId, filter, id)) {
		return;
	}
	PropertyStringImpl p = new PropertyStringImpl(id, value);
	p.setQueryName(id);
	props.addProperty(p);
}
 
Example #15
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addAspectProperties(CMISNodeInfo info, String filter, PropertiesImpl result)
{
    if (getRequestCmisVersion().equals(CmisVersion.CMIS_1_1))
    {
        Set<String> propertyIds = new HashSet<>();
        Set<String> filterSet = splitFilter(filter);

        Set<QName> aspects = info.getNodeAspects();
        for (QName aspect : aspects)
        {
            TypeDefinitionWrapper aspectType = getOpenCMISDictionaryService().findNodeType(aspect);
            if (aspectType == null)
            {
                continue;
            }

            for (PropertyDefinitionWrapper propDef : aspectType.getProperties())
            {
                if (propertyIds.contains(propDef.getPropertyId()))
                {
                    // skip properties that have already been added
                    continue;
                }

                if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName())))
                {
                    // skip properties that are not in the filter
                    continue;
                }

                Serializable value = propDef.getPropertyAccessor().getValue(info);
                result.addProperty(getProperty(propDef.getPropertyDefinition().getPropertyType(), propDef, value));

                // mark property as 'added'
                propertyIds.add(propDef.getPropertyId());
            }
        }
    }
}
 
Example #16
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addPropertyDateTime(PropertiesImpl props, String typeId, Set<String> filter, String id,
		GregorianCalendar value) {

	if (!checkAddProperty(props, typeId, filter, id)) {
		return;
	}

	PropertyDateTimeImpl p = new PropertyDateTimeImpl(id, value);
	p.setQueryName(id);
	props.addProperty(p);
}
 
Example #17
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addPropertyBoolean(PropertiesImpl props, String typeId, Set<String> filter, String id, boolean value) {
	if (!checkAddProperty(props, typeId, filter, id)) {
		return;
	}

	PropertyBooleanImpl p = new PropertyBooleanImpl(id, value);
	p.setQueryName(id);
	props.addProperty(p);
}
 
Example #18
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private List<ObjectData> createChangeEvents(long time, Map<String, Serializable> values)
{
    List<ObjectData> result = new ArrayList<ObjectData>();

    if ((values == null) || (values.size() == 0))
    {
        return result;
    }

    GregorianCalendar changeTime = new GregorianCalendar();
    changeTime.setTimeInMillis(time);

    String appPath = "/" + CMIS_CHANGELOG_AUDIT_APPLICATION + "/";

    for (Entry<String, Serializable> entry : values.entrySet())
    {
        if ((entry.getKey() == null) || (!(entry.getValue() instanceof Map)))
        {
            continue;
        }

        String path = entry.getKey();
        if (!path.startsWith(appPath))
        {
            continue;
        }

        ChangeType changeType = null;
        String changePath = path.substring(appPath.length()).toLowerCase();
        for (ChangeType c : ChangeType.values())
        {
            if (changePath.startsWith(c.value().toLowerCase()))
            {
                changeType = c;
                break;
            }
        }

        if (changeType == null)
        {
            continue;
        }

        Map<String, Serializable> valueMap = (Map<String, Serializable>) entry.getValue();
        String objectId = (String) valueMap.get(CMISChangeLogDataExtractor.KEY_OBJECT_ID);

        // build object
        ObjectDataImpl object = new ObjectDataImpl();
        result.add(object);

        PropertiesImpl properties = new PropertiesImpl();
        object.setProperties(properties);
        PropertyIdImpl objectIdProperty = new PropertyIdImpl(PropertyIds.OBJECT_ID, objectId);
        properties.addProperty(objectIdProperty);

        ChangeEventInfoDataImpl changeEvent = new ChangeEventInfoDataImpl();
        object.setChangeEventInfo(changeEvent);
        changeEvent.setChangeType(changeType);
        changeEvent.setChangeTime(changeTime);
    }

    return result;
}
 
Example #19
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 #20
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public List<ObjectData> getFolderLastChanges(long minDate, int max) {
	
	StringBuffer query = new StringBuffer(" _entity.tenantId=?1 and _entity.date >= ?2 ");
	query.append(" and _entity.event in ('");
	query.append(FolderEvent.CREATED);
	query.append("','");
	query.append(FolderEvent.RENAMED);
	query.append("','");
	query.append(FolderEvent.MOVED);
	query.append("','");		
	query.append(FolderEvent.DELETED);
	query.append("')");

	List<FolderHistory> entries = new ArrayList<FolderHistory>();

	try {
		entries = folderHistoryDao.findByWhere(query.toString(),
				new Object[] { getRoot().getTenantId(), new Date(minDate) }, "order by _entity.date", max);
	} catch (PersistenceException e) {
		log.error(e.getMessage(), e);
	}

	List<ObjectData> ods = new ArrayList<ObjectData>(entries.size());
	Date date = null;
	for (FolderHistory logEntry : entries) {
		ObjectDataImpl od = new ObjectDataImpl();
		ChangeEventInfoDataImpl cei = new ChangeEventInfoDataImpl();
		
		// change type
		String eventId = logEntry.getEvent();
		ChangeType changeType;
		if (FolderEvent.CREATED.toString().equals(eventId)) {
			changeType = ChangeType.CREATED;
		} else if (FolderEvent.RENAMED.toString().equals(eventId) || FolderEvent.MOVED.toString().equals(eventId) ) {
			changeType = ChangeType.UPDATED;
		} else if (FolderEvent.DELETED.toString().equals(eventId)) {
			changeType = ChangeType.DELETED;
		} else {
			continue;
		}
		cei.setChangeType(changeType);
		
		// change time
		GregorianCalendar changeTime = (GregorianCalendar) Calendar.getInstance();
		date = logEntry.getDate();
		changeTime.setTime(date);
		cei.setChangeTime(changeTime);
		od.setChangeEventInfo(cei);
		
		// properties: id, doc type
		PropertiesImpl properties = new PropertiesImpl();
		properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_ID, ID_PREFIX_FLD + logEntry.getFolderId()));
		properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()));
		od.setProperties(properties);
		ods.add(od);
	}
	return ods;
}
 
Example #21
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public List<ObjectData> getDocumentLastChanges(long minDate, int max) {
	
	StringBuffer query = new StringBuffer(" _entity.tenantId=?1 and _entity.date >= ?2 ");
	query.append(" and _entity.event in ('");
	query.append(DocumentEvent.STORED);
	query.append("','");
	query.append(DocumentEvent.CHECKEDIN);
	query.append("','");
	query.append(DocumentEvent.MOVED);
	query.append("','");		
	query.append(DocumentEvent.RENAMED);
	query.append("','");
	query.append(DocumentEvent.DELETED);
	query.append("')");

	List<DocumentHistory> entries = new ArrayList<DocumentHistory>();

	try {
		entries = historyDao.findByWhere(query.toString(),
				new Object[] { getRoot().getTenantId(), new Date(minDate) }, "order by _entity.date", max);
	} catch (PersistenceException e) {
		log.error(e.getMessage(), e);
	}

	List<ObjectData> ods = new ArrayList<ObjectData>(entries.size());
	Date date = null;
	for (DocumentHistory logEntry : entries) {
		ObjectDataImpl od = new ObjectDataImpl();
		ChangeEventInfoDataImpl cei = new ChangeEventInfoDataImpl();
		
		// change type
		String eventId = logEntry.getEvent();
		ChangeType changeType;
		if (DocumentEvent.STORED.toString().equals(eventId)) {
			changeType = ChangeType.CREATED;
		} else if (DocumentEvent.CHECKEDIN.toString().equals(eventId)
				|| DocumentEvent.RENAMED.toString().equals(eventId)
				|| DocumentEvent.MOVED.toString().equals(eventId)) {
			changeType = ChangeType.UPDATED;
		} else if (DocumentEvent.DELETED.toString().equals(eventId)) {
			changeType = ChangeType.DELETED;
		} else {
			continue;
		}
		cei.setChangeType(changeType);
		
		// change time
		GregorianCalendar changeTime = (GregorianCalendar) Calendar.getInstance();
		date = logEntry.getDate();
		changeTime.setTime(date);
		cei.setChangeTime(changeTime);
		od.setChangeEventInfo(cei);
		
		// properties: id, doc type
		PropertiesImpl properties = new PropertiesImpl();
		properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_ID, ID_PREFIX_DOC + logEntry.getDocId()));
		properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value()));
		od.setProperties(properties);
		ods.add(od);
	}
	return ods;
}
 
Example #22
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 4 votes vote down vote up
static void addPropertyInteger(PropertiesImpl props, TypeDefinition type, Set<String> filter, String id, long value) {
	addPropertyBigInteger(props, type, filter, id,
			BigInteger.valueOf(value));
}
 
Example #23
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Adds the default value of property if defined.
 */
@SuppressWarnings("unchecked")
private static boolean addPropertyDefault(PropertiesImpl props, PropertyDefinition<?> propDef) {
	if ((props == null) || (props.getProperties() == null)) {
		throw new IllegalArgumentException("Props must not be null!");
	}

	if (propDef == null) {
		return false;
	}

	List<?> defaultValue = propDef.getDefaultValue();
	if ((defaultValue != null) && (!defaultValue.isEmpty())) {
		switch (propDef.getPropertyType()) {
		case BOOLEAN:
			PropertyBooleanImpl p = new PropertyBooleanImpl(propDef.getId(), (List<Boolean>) defaultValue);
			p.setQueryName(propDef.getId());
			props.addProperty(p);
			break;
		case DATETIME:
			PropertyDateTimeImpl p1 = new PropertyDateTimeImpl(propDef.getId(),
					(List<GregorianCalendar>) defaultValue);
			p1.setQueryName(propDef.getId());
			props.addProperty(p1);
			break;
		case DECIMAL:
			PropertyDecimalImpl p3 = new PropertyDecimalImpl(propDef.getId(), (List<BigDecimal>) defaultValue);
			p3.setQueryName(propDef.getId());
			props.addProperty(p3);
			break;
		case HTML:
			PropertyHtmlImpl p4 = new PropertyHtmlImpl(propDef.getId(), (List<String>) defaultValue);
			p4.setQueryName(propDef.getId());
			props.addProperty(p4);
			break;
		case ID:
			PropertyIdImpl p5 = new PropertyIdImpl(propDef.getId(), (List<String>) defaultValue);
			p5.setQueryName(propDef.getId());
			props.addProperty(p5);
			break;
		case INTEGER:
			PropertyIntegerImpl p6 = new PropertyIntegerImpl(propDef.getId(), (List<BigInteger>) defaultValue);
			p6.setQueryName(propDef.getId());
			props.addProperty(p6);
			break;
		case STRING:
			PropertyStringImpl p7 = new PropertyStringImpl(propDef.getId(), (List<String>) defaultValue);
			p7.setQueryName(propDef.getId());
			props.addProperty(p7);
			break;
		case URI:
			PropertyUriImpl p8 = new PropertyUriImpl(propDef.getId(), (List<String>) defaultValue);
			p8.setQueryName(propDef.getId());
			props.addProperty(p8);
			break;
		default:
			throw new RuntimeException("Unknown datatype! Spec change?");
		}

		return true;
	}

	return false;
}
 
Example #24
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void addPropertyInteger(PropertiesImpl props, String typeId, Set<String> filter, String id, long value) {
	addPropertyBigInteger(props, typeId, filter, id, BigInteger.valueOf(value));
}