Java Code Examples for org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl#setProperties()

The following examples show how to use org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl#setProperties() . 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: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Compiles an object type object from a document or folder
 * 
 * @param context the call context
 * @param object the persistent object
 * @param filter optional filter
 * @param includeAllowableActions if the allowable actions must be included
 * @param includeAcl if the ACL must be included
 * @param objectInfos informations
 * 
 * @return the object
 */
private ObjectData compileObjectType(CallContext context, PersistentObject object, Set<String> filter,
		boolean includeAllowableActions, boolean includeAcl, ObjectInfoHandler objectInfos) {

	ObjectDataImpl result = new ObjectDataImpl();
	ObjectInfoImpl objectInfo = new ObjectInfoImpl();

	result.setProperties(compileProperties(object, filter, objectInfo));

	if (includeAllowableActions) {
		result.setAllowableActions(compileAllowableActions(object));
	}

	if (includeAcl) {
		result.setAcl(compileAcl(object));
		result.setIsExactAcl(true);
	}

	if ((context != null) && context.isObjectInfoRequired() && (objectInfos != null)) {
		objectInfo.setObject(result);
		// objectInfo.setVersionSeriesId(getId(object));
		objectInfos.addObjectInfo(objectInfo);
	}

	return result;
}
 
Example 2
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 6 votes vote down vote up
static ObjectDataImpl toObjectData(CmisRepositoryConfiguration config,
		CallContext context,
		TypeDefinition type,
		Object object,
		boolean root,
		Set<String> filter,
		ObjectInfoHandler objectInfos) {

	ObjectDataImpl result = new ObjectDataImpl();
	ObjectInfoImpl objectInfo = new ObjectInfoImpl();

	compileObjectMetadata(objectInfo, type);

	result.setProperties(compileProperties(config, type, object, root, filter, objectInfo));

	result.setAllowableActions(compileAllowableActions(type, object, false, false));

	if (context.isObjectInfoRequired()) {
		objectInfo.setObject(result);
		objectInfos.addObjectInfo(objectInfo);
	}

	return result;
}
 
Example 3
Source File: Converter.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Converts a CMIS object
 * 
 * @param object the object to convert
 * 
 * @return the converted object
 */
public static ObjectData convert(CmisObjectType object) {
	if (object == null) {
		return null;
	}

	ObjectDataImpl result = new ObjectDataImpl();

	result.setAcl(convert(object.getAcl(), object.isExactACL()));
	result.setAllowableActions(convert(object.getAllowableActions()));
	if (object.getChangeEventInfo() != null) {
		ChangeEventInfoDataImpl changeEventInfo = new ChangeEventInfoDataImpl();
		if (object.getChangeEventInfo().getChangeTime() != null) {
			changeEventInfo.setChangeTime(object.getChangeEventInfo().getChangeTime().toGregorianCalendar());
		}
		changeEventInfo.setChangeType(convert(ChangeType.class, object.getChangeEventInfo().getChangeType()));
		convertExtension(object.getChangeEventInfo(), changeEventInfo);

		result.setChangeEventInfo(changeEventInfo);
	}
	result.setIsExactAcl(object.isExactACL());
	result.setPolicyIds(convert(object.getPolicyIds()));
	result.setProperties(convert(object.getProperties()));
	List<ObjectData> relationships = new ArrayList<ObjectData>();
	for (CmisObjectType cmisObject : object.getRelationship()) {
		relationships.add(convert(cmisObject));
	}
	result.setRelationships(relationships);
	List<RenditionData> renditions = new ArrayList<RenditionData>();
	for (CmisRenditionType rendition : object.getRendition()) {
		renditions.add(convert(rendition));
	}
	result.setRenditions(renditions);

	// handle extensions
	convertExtension(object, result);

	return result;
}
 
Example 4
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 5
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 6
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private ObjectData createCMISObjectImpl(final CMISNodeInfo info, Properties nodeProps, String filter,
        boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
        boolean includePolicyIds, boolean includeAcl)
{
    final ObjectDataImpl result = new ObjectDataImpl();

    // set allowable actions
    if (includeAllowableActions)
    {
        result.setAllowableActions(getAllowableActions(info));
    }

    // set policy ids
    if (includePolicyIds)
    {
        result.setPolicyIds(new PolicyIdListImpl());
    }

    if (info.isRelationship())
    {
        // set properties
        result.setProperties(getAssocProperties(info, filter));

        // set ACL
        if (includeAcl)
        {
            // association have no ACL - return an empty list of ACEs
            result.setAcl(new AccessControlListImpl((List<Ace>) Collections.EMPTY_LIST));
            result.setIsExactAcl(Boolean.FALSE);
        }
    }
    else
    {
        // set properties
        result.setProperties(nodeProps);

        // set relationships
        if (includeRelationships != IncludeRelationships.NONE)
        {
            result.setRelationships(getRelationships(info.getNodeRef(), includeRelationships));
        }

        // set renditions
        if (!RENDITION_NONE.equals(renditionFilter))
        {
            List<RenditionData> renditions = getRenditions(info.getNodeRef(), renditionFilter, null, null);
            if ((renditions != null) && (!renditions.isEmpty()))
            {
                result.setRenditions(renditions);
            }
            else
            {
            	result.setRenditions(Collections.EMPTY_LIST);
            }
        }

        // set ACL
        if (includeAcl)
        {
        	AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
        	{
	@Override
	public Void doWork() throws Exception
	{
	    Acl acl = getACL(info.getCurrentNodeNodeRef(), false);
              if (acl != null)
              {
	        result.setAcl(acl);
	        result.setIsExactAcl(acl.isExact());
              }
		return null;
	}
        	});
        }

        // add aspects
        List<CmisExtensionElement> extensions = getAspectExtensions(info, filter, result.getProperties()
                .getProperties().keySet());

        if (!extensions.isEmpty())
        {
            result.getProperties().setExtensions(
                    Collections.singletonList((CmisExtensionElement) new CmisExtensionElementImpl(
                            ALFRESCO_EXTENSION_NAMESPACE, ASPECTS, null, extensions)));
        }
    }
    return result;
}
 
Example 7
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 8
Source File: CmisUtils.java    From iaf with Apache License 2.0 4 votes vote down vote up
public static ObjectData xml2ObjectData(Element cmisElement, IPipeLineSession context) {
	ObjectDataImpl impl = new ObjectDataImpl();

	// Handle allowable actions
	Element allowableActionsElem = XmlUtils.getFirstChildTag(cmisElement, "allowableActions");
	if(allowableActionsElem != null) {
		AllowableActionsImpl allowableActions = new AllowableActionsImpl();
		Set<Action> actions = EnumSet.noneOf(Action.class);

		Iterator<Node> actionIterator = XmlUtils.getChildTags(allowableActionsElem, "action").iterator();
		while (actionIterator.hasNext()) {
			String property = XmlUtils.getStringValue((Element) actionIterator.next());
			actions.add(Action.fromValue(property));
		}

		allowableActions.setAllowableActions(actions);
		impl.setAllowableActions(allowableActions);
	}

	// Handle isExactAcl
	String isExactAcl = XmlUtils.getChildTagAsString(cmisElement, "isExactAcl");
	if(isExactAcl != null) {
		impl.setIsExactAcl(Boolean.parseBoolean(isExactAcl));
	}

	// If the original object exists copy the permissions over. These cannot (and shouldn't) be changed)
	if(context != null) {
		CmisObject object = (CmisObject) context.get(CmisUtils.ORIGINAL_OBJECT_KEY);
		if(object != null) {
			impl.setAcl(object.getAcl());
		}
	}

	// Handle policyIds
	Element policyIdsElem = XmlUtils.getFirstChildTag(cmisElement, "policyIds");
	if(policyIdsElem != null) {
		PolicyIdListImpl policyIdList = new PolicyIdListImpl();
		List<String> policies = new ArrayList<String>();

		Iterator<Node> policyIterator = XmlUtils.getChildTags(allowableActionsElem, "policyId").iterator();
		while (policyIterator.hasNext()) {
			String policyId = XmlUtils.getStringValue((Element) policyIterator.next());
			policies.add(policyId);
		}

		policyIdList.setPolicyIds(policies);
		impl.setPolicyIds(policyIdList);
	}

	// Handle properties
	impl.setProperties(CmisUtils.processProperties(cmisElement));

	Element relationshipsElem = XmlUtils.getFirstChildTag(cmisElement, "relationships");
	if(relationshipsElem != null) {
		List<ObjectData> relationships = new ArrayList<ObjectData>();
		for (Node type : XmlUtils.getChildTags(relationshipsElem, "relation")) {
			ObjectData data = xml2ObjectData((Element) type, null);
			relationships.add(data);
		}
		impl.setRelationships(relationships);
	}

	impl.setRenditions(null);
	impl.setExtensions(null);
	impl.setChangeEventInfo(null);

	return impl;
}