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

The following examples show how to use org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl. 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 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 #2
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 #3
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 #4
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 #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> 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 #6
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 #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: 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();
    }
}