Java Code Examples for org.apache.chemistry.opencmis.commons.data.Properties#getProperties()

The following examples show how to use org.apache.chemistry.opencmis.commons.data.Properties#getProperties() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: CmisServiceBridge.java    From spring-content with Apache License 2.0 6 votes vote down vote up
static boolean checkAddProperty(Properties properties, TypeDefinition type, Set<String> filter, String id) {
	if ((properties == null) || (properties.getProperties() == null)) {
		throw new IllegalArgumentException("Properties must not be null!");
	}

	if (id == null) {
		throw new IllegalArgumentException("Id must not be null!");
	}

	if (!type.getPropertyDefinitions().containsKey(id)) {
		throw new IllegalArgumentException("Unknown property: " + id);
	}

	String queryName = type.getPropertyDefinitions().get(id).getQueryName();

	if ((queryName != null) && (filter != null)) {
		if (!filter.contains(queryName)) {
			return false;
		} else {
			filter.remove(queryName);
		}
	}

	return true;
}
 
Example 8
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean checkAddProperty(Properties properties, String typeId, Set<String> filter, String id) {
	try {
		if ((properties == null) || (properties.getProperties() == null)) {
			throw new IllegalArgumentException("Properties must not be null!");
		}

		if (id == null) {
			throw new IllegalArgumentException("Id must not be null!");
		}

		TypeDefinition type = types.getType(typeId);
		if (type == null) {
			throw new IllegalArgumentException("Unknown type: " + typeId);
		}

		if (!type.getPropertyDefinitions().containsKey(id)) {
			throw new IllegalArgumentException("Unknown property: " + id);
		}

		String queryName = type.getPropertyDefinitions().get(id).getQueryName();

		if ((queryName != null) && (filter != null)) {
			if (!filter.contains(queryName)) {
				return false;
			} else {
				filter.remove(queryName);
			}
		}

		return true;
	} catch (Throwable e) {
		log.warn(e.getMessage(), e);
	}

	return false;
}
 
Example 9
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 10
Source File: CmisRepository.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkAddProperty(Properties properties, String typeId, Set<String> filter, String id) {
	if ((properties == null) || (properties.getProperties() == null)) {
		throw new IllegalArgumentException("Properties must not be null!");
	}

	if (id == null) {
		throw new IllegalArgumentException("Id must not be null!");
	}

	TypeDefinition type = types.getType(typeId);
	if (type == null) {
		throw new IllegalArgumentException("Unknown type: " + typeId);
	}
	if (!type.getPropertyDefinitions().containsKey(id)) {
		throw new IllegalArgumentException("Unknown property: " + id);
	}

	String queryName = type.getPropertyDefinitions().get(id).getQueryName();

	if ((queryName != null) && (filter != null)) {
		if (!filter.contains(queryName)) {
			return false;
		} else {
			filter.remove(queryName);
		}
	}

	return true;
}
 
Example 11
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * CMIS createDocument
 * 
 * @param context call context
 * @param properties the folder's properties
 * @param folderId identifier of the parent folder
 * @param contentStream binary content of the file to create
 * @param versioningState state of the version
 * 
 * @return the new document's identifier
 */
public String createDocument(CallContext context, Properties properties, String folderId,
		ContentStream contentStream, VersioningState versioningState) {

	debug("createDocument " + folderId);

	validatePermission(folderId, context, Permission.WRITE);

	try {

		// check properties
		if ((properties == null) || (properties.getProperties() == null))
			throw new CmisInvalidArgumentException("Properties must be set!");

		// // check versioning state
		// if (versioningState != null && VersioningState.NONE !=
		// versioningState) {
		// throw new CmisConstraintException("Versioning not supported!");
		// }

		// check type
		String typeId = getTypeId(properties);
		TypeDefinition type = types.getType(typeId);
		if (type == null)
			throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");

		User user = getSessionUser();

		// check the name
		String name = getStringProperty(properties, PropertyIds.NAME);
		if (name == null)
			throw new CmisNameConstraintViolationException("Name is not valid!");

		String fileName = getStringProperty(properties, PropertyIds.CONTENT_STREAM_FILE_NAME);
		if (fileName == null)
			fileName = getStringProperty(properties, "Filename");
		if (fileName == null) {
			fileName = name;
			if (name.lastIndexOf('.') > 0)
				name = fileName.substring(0, name.lastIndexOf('.'));
		}
		if (!isValidName(fileName))
			throw new CmisNameConstraintViolationException("File name is not valid!");

		// get parent Folder
		Folder parent = getFolder(folderId);
		if (parent == null)
			throw new CmisObjectNotFoundException("Parent is not a folder!");

		Document document = new Document();
		updateDocumentMetadata(document, properties, true);
		document.setTenantId(user.getTenantId());
		document.setFileName(fileName);
		document.setFolder(getFolder(folderId));
		document.setLanguage(user.getLanguage());

		DocumentHistory transaction = new DocumentHistory();
		transaction.setUser(user);
		transaction.setSessionId(sid);

		document = documentManager.create(new BufferedInputStream(contentStream.getStream(), BUFFER_SIZE), document,
				transaction);

		return getId(document);
	} catch (Throwable t) {
		return (String) catchError(t);
	}
}
 
Example 12
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * CMIS moveObject
 * 
 * @param context call context
 * @param properties the folder's properties
 * @param folderId identifier of the parent folder
 * 
 * @return the created folder's identifier
 */
public String createFolder(CallContext context, Properties properties, String folderId) {
	debug("createFolder " + folderId);

	validatePermission(folderId, context, Permission.WRITE);

	try {

		// check properties
		if ((properties == null) || (properties.getProperties() == null))
			throw new CmisInvalidArgumentException("Properties must be set!");

		// check type
		String typeId = getTypeId(properties);
		TypeDefinition type = types.getType(typeId);
		if (type == null)
			throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");

		// check the name
		String name = getStringProperty(properties, PropertyIds.NAME);
		if (!isValidName(name))
			throw new CmisNameConstraintViolationException("Name is not valid.");

		// get parent File
		Folder parent = getFolder(folderId);
		if (parent == null)
			throw new CmisObjectNotFoundException("Parent is not a folder!");

		FolderHistory transaction = new FolderHistory();
		transaction.setUser(getSessionUser());
		transaction.setSessionId(sid);

		Folder folder = null;
		Folder newFolder = new Folder(name);
		newFolder.setTenantId(getSessionUser().getTenantId());
		folder = folderDao.create(parent, newFolder, true, transaction);

		return getId(folder);
	} catch (Throwable t) {
		return (String) catchError(t);
	}
}
 
Example 13
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public String create(
        String repositoryId, Properties properties, String folderId, ContentStream contentStream,
        VersioningState versioningState, List<String> policies, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    // check properties
    if (properties == null || properties.getProperties() == null)
    {
        throw new CmisInvalidArgumentException("Properties must be set!");
    }

    // get the type
    String objectTypeId = connector.getObjectTypeIdProperty(properties);

    // find the type
    TypeDefinitionWrapper type = connector.getOpenCMISDictionaryService().findType(objectTypeId);
    if (type == null)
    {
        throw new CmisInvalidArgumentException("Type '" + objectTypeId + "' is unknown!");
    }

    // create object
    String newId = null;
    switch (type.getBaseTypeId())
    {
    case CMIS_DOCUMENT:
        versioningState = getDocumentDefaultVersioningState(versioningState, type);
        newId = createDocument(repositoryId, properties, folderId, contentStream, versioningState, policies, null,
                null, extension);
        break;
    case CMIS_FOLDER:
        newId = createFolder(repositoryId, properties, folderId, policies, null, null, extension);
        break;
    case CMIS_POLICY:
        newId = createPolicy(repositoryId, properties, folderId, policies, null, null, extension);
        break;
    case CMIS_ITEM:
        newId = createItem(repositoryId, properties, folderId, policies, null, null, extension);
        break;
    default:
        break;

    }

    // check new object id
    if (newId == null)
    {
        throw new CmisRuntimeException("Creation failed!");
    }

	boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired)
    {
        try
        {
            getObjectInfo(repositoryId, newId, "*", IncludeRelationships.NONE);
        }
        catch (InvalidNodeRefException e)
        {
            throw new CmisRuntimeException("Creation failed! New object not found!");
        }
    }

    // return the new object id
    return newId;
}
 
Example 14
Source File: CmisRepository.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks and compiles a property set that can be written to disc.
 */
private Properties compileProperties(String typeId, String creator, GregorianCalendar creationDate, String modifier,
                                     Properties properties) {
	PropertiesImpl result = new PropertiesImpl();
	Set<String> addedProps = new HashSet<String>();

	if ((properties == null) || (properties.getProperties() == null)) {
		throw new CmisConstraintException("No properties!");
	}

	// get the property definitions
	TypeDefinition type = types.getType(typeId);
	if (type == null) {
		throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
	}

	// check if all required properties are there
	for (PropertyData<?> prop : properties.getProperties().values()) {
		PropertyDefinition<?> propType = type.getPropertyDefinitions().get(prop.getId());

		// do we know that property?
		if (propType == null) {
			throw new CmisConstraintException("Property '" + prop.getId() + "' is unknown!");
		}

		// can it be set?
		if ((propType.getUpdatability() == Updatability.READONLY)) {
			throw new CmisConstraintException("Property '" + prop.getId() + "' is readonly!");
		}

		// empty properties are invalid
		if (isEmptyProperty(prop)) {
			throw new CmisConstraintException("Property '" + prop.getId() + "' must not be empty!");
		}

		// add it
		result.addProperty(prop);
		addedProps.add(prop.getId());
	}

	// check if required properties are missing
	for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
		if (!addedProps.contains(propDef.getId()) && (propDef.getUpdatability() != Updatability.READONLY)) {
			if (!addPropertyDefault(result, propDef) && propDef.isRequired()) {
				throw new CmisConstraintException("Property '" + propDef.getId() + "' is required!");
			}
		}
	}

	addPropertyId(result, typeId, null, PropertyIds.OBJECT_TYPE_ID, typeId);
	addPropertyString(result, typeId, null, PropertyIds.CREATED_BY, creator);
	addPropertyDateTime(result, typeId, null, PropertyIds.CREATION_DATE, creationDate);
	addPropertyString(result, typeId, null, PropertyIds.LAST_MODIFIED_BY, modifier);

	return result;
}