Java Code Examples for org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException

The following examples show how to use org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException. These examples are extracted from open source projects. 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
public ObjectInfo getObjectInfo(String objectId, ObjectInfoHandler handler) {
	debug("getObjectInfo " + objectId);
	validatePermission(objectId, null, null);

	try {
		// check id
		if ((objectId == null))
			throw new CmisInvalidArgumentException("Object Id must be set.");

		ObjectInfoImpl info = new ObjectInfoImpl();
		PersistentObject object = getObject(objectId);
		compileProperties(object, null, info);
		ObjectData data = compileObjectType(null, object, null, true, true, handler);
		info.setObject(data);
		return info;
	} catch (Throwable t) {
		log.warn("Not able to retrieve object {}", objectId);
		return (ObjectInfo) catchError(t);
	}
}
 
Example 2
public String getNameProperty(Properties properties, String fallback)
{
    String name = getStringProperty(properties, PropertyIds.NAME);
    if ((name == null) || (name.trim().length() == 0))
    {
        if (fallback == null)
        {
            throw new CmisInvalidArgumentException("Property " + PropertyIds.NAME + " must be set!");
        }
        else
        {
            name = fallback;
        }
    }

    return name;
}
 
Example 3
@Override
public ContentStream getContentStream(
        String repositoryId, String objectId, String streamId, BigInteger offset,
        BigInteger length, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");

    // relationships cannot have content
    if (info.isVariant(CMISObjectVariant.ASSOC))
    {
        throw new CmisInvalidArgumentException("Object is a relationship and cannot have content!");
    }

    // now get it
    return connector.getContentStream(info, streamId, offset, length);
}
 
Example 4
@Override
public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
        Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
        BigInteger maxItems, BigInteger skipCount, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    if (searchAllVersions.booleanValue())
    {
        throw new CmisInvalidArgumentException("Search all version is not supported!");
    }

    return connector.query(
            statement, includeAllowableActions, includeRelationships, renditionFilter,
            maxItems, skipCount);
}
 
Example 5
/**
 * 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 6
/**
 * Throws an exception if the given list is {@code null} or empty or
 * invalid.
 */
protected void checkBulkUpdateList(List<BulkUpdateObjectIdAndChangeToken> list) {
    if (list == null) {
        throw new CmisInvalidArgumentException("Object Id list must be set!");
    }

    if (list.isEmpty()) {
        throw new CmisInvalidArgumentException("Object Id list must not be empty!");
    }

    for (BulkUpdateObjectIdAndChangeToken entry : list) {
        if (entry == null) {
            throw new CmisInvalidArgumentException("Object Id list has gaps!");
        }

        if (entry.getId() == null) {
            throw new CmisInvalidArgumentException("Object Id list contains an entry without ID!");
        }

        if (entry.getId().length() == 0) {
            throw new CmisInvalidArgumentException("Object Id list contains an entry with an empty ID!");
        }
    }
}
 
Example 7
/**
 * Checks the depth parameter if it complies with CMIS specification and
 * returns the default value if {@code depth} is {@code null}.
 */
protected BigInteger getTypesDepth(BigInteger depth) {
    if (depth == null) {
        return defaultTypesDepth;
    }

    if (depth.compareTo(BigInteger.ZERO) == 0) {
        throw new CmisInvalidArgumentException("depth must not be 0!");
    }

    if (depth.compareTo(MINUS_ONE) == -1) {
        throw new CmisInvalidArgumentException("depth must not be <-1!");
    }

    return depth;
}
 
Example 8
/**
 * Checks the depth parameter if it complies with CMIS specification and
 * returns the default value if {@code depth} is {@code null}.
 */
protected BigInteger getDepth(BigInteger depth) {
    if (depth == null) {
        return defaultDepth;
    }

    if (depth.compareTo(BigInteger.ZERO) == 0) {
        throw new CmisInvalidArgumentException("depth must not be 0!");
    }

    if (depth.compareTo(MINUS_ONE) == -1) {
        throw new CmisInvalidArgumentException("depth must not be <-1!");
    }

    return depth;
}
 
Example 9
private String getType(String tableName)
{
    TypeDefinitionWrapper typeDef = dictionaryService.findTypeByQueryName(tableName);
    if (typeDef == null)
    {
        throw new CmisInvalidArgumentException("Unknown type: " + tableName);
    }
    if(!typeDef.isBaseType())
    {
        throw new CmisInvalidArgumentException("Not a base type: " + tableName);
    }
    if(!typeDef.getTypeDefinition(false).isQueryable())
    {
        throw new CmisInvalidArgumentException("Type is not queryable: " + tableName);
    }
    return typeDef.getAlfrescoClass().toString();
}
 
Example 10
@Override
public <Q, S, E extends Throwable> String getLuceneSortField(LuceneQueryParserAdaptor<Q, S, E> lqpa) throws E
{
    String field = getLuceneFieldName();
    // need to find the real field to use
    PropertyDefinition propertyDef = dictionaryService.getProperty(QName.createQName(field.substring(1)));

    if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
    {
        throw new CmisInvalidArgumentException("Order on content properties is not curently supported");
    }
    else if ((propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) || (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)))
    {
        field = lqpa.getSortField(field);
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME))
    {
        field = lqpa.getDatetimeSortField(field, propertyDef);
    }        

    return field;
}
 
Example 11
/**
 * CMIS getTypesDescendants
 * 
 * @param context call context
 * @param typeId id of the type
 * @param depth depth specification
 * @param includePropertyDefinitions if the properties definition must be included
 *  
 * @return list of definitions
 */
public List<TypeDefinitionContainer> getTypesDescendants(CallContext context, String typeId, BigInteger depth,
		Boolean includePropertyDefinitions) {
	List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();

	// check depth
	int d = (depth == null ? -1 : depth.intValue());
	if (d == 0) {
		throw new CmisInvalidArgumentException("Depth must not be 0!");
	}

	// set property definition flag to default value if not set
	boolean ipd = (includePropertyDefinitions == null ? false : includePropertyDefinitions.booleanValue());

	if (typeId == null) {
		result.add(getTypesDescendants(d, types.get(FOLDER_TYPE_ID), ipd));
		result.add(getTypesDescendants(d, types.get(DOCUMENT_TYPE_ID), ipd));
		// result.add(getTypesDescendants(depth,
		// fTypes.get(RELATIONSHIP_TYPE_ID), includePropertyDefinitions));
		// result.add(getTypesDescendants(depth, fTypes.get(POLICY_TYPE_ID),
		// includePropertyDefinitions));
	} else {
		TypeDefinitionContainer tc = types.get(typeId);
		if (tc != null) {
			result.add(getTypesDescendants(d, tc, ipd));
		}
	}

	return result;
}
 
Example 12
/**
 * 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 13
public void checkIfUseful(String what)
{
    switch (objecVariant)
    {
    case INVALID_ID:
        throw new CmisInvalidArgumentException(what + " id is invalid: " + objectId);
    case NOT_EXISTING:
        throw new CmisObjectNotFoundException(what + " not found: " + objectId);
    case NOT_A_CMIS_OBJECT:
        throw new CmisObjectNotFoundException(what + " is not a CMIS object: " + objectId);
    case PERMISSION_DENIED:
        throw new CmisPermissionDeniedException("Permission denied!");
    }
}
 
Example 14
public void checkIfFolder(String what)
{
    checkIfUseful(what);
    if (objecVariant != CMISObjectVariant.FOLDER)
    {
        throw new CmisInvalidArgumentException(what + " is not a folder!");
    }
}
 
Example 15
public void addSecondaryTypes(NodeRef nodeRef, List<String> secondaryTypes)
{
	if(secondaryTypes != null && secondaryTypes.size() > 0)
	{
 	for(String secondaryType : secondaryTypes)
 	{
         TypeDefinitionWrapper type = getType(secondaryType);
         if (type == null)
         {
             throw new CmisInvalidArgumentException("Invalid secondaryType: " + secondaryType);
         }
 		nodeService.addAspect(nodeRef, type.getAlfrescoName(), null);
 	}
	}
}
 
Example 16
public void removeSecondaryTypes(NodeRef nodeRef, List<String> secondaryTypes)
{
	if(secondaryTypes != null && secondaryTypes.size() > 0)
	{
 	for(String secondaryType : secondaryTypes)
 	{
         TypeDefinitionWrapper type = getType(secondaryType);
         if (type == null)
         {
             throw new CmisInvalidArgumentException("Invalid secondaryType: " + secondaryType);
         }
 		nodeService.removeAspect(nodeRef, type.getAlfrescoName());
 	}
	}
}
 
Example 17
public String getObjectTypeIdProperty(Properties properties)
{
    String objectTypeId = getIdProperty(properties, PropertyIds.OBJECT_TYPE_ID);
    if ((objectTypeId == null) || (objectTypeId.trim().length() == 0))
    {
        throw new CmisInvalidArgumentException("Property " + PropertyIds.OBJECT_TYPE_ID + " must be set!");
    }

    return objectTypeId;
}
 
Example 18
public String getSourceIdProperty(Properties properties)
{
    String id = getIdProperty(properties, PropertyIds.SOURCE_ID);
    if ((id == null) || (id.trim().length() == 0))
    {
        throw new CmisInvalidArgumentException("Property " + PropertyIds.SOURCE_ID + " must be set!");
    }

    return id;
}
 
Example 19
public String getTargetIdProperty(Properties properties)
{
    String id = getIdProperty(properties, PropertyIds.TARGET_ID);
    if ((id == null) || (id.trim().length() == 0))
    {
        throw new CmisInvalidArgumentException("Property " + PropertyIds.TARGET_ID + " must be set!");
    }

    return id;
}
 
Example 20
@Override
public ObjectData getFolderParent(String repositoryId, String folderId, String filter, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    // get the node ref
    CMISNodeInfo info = getOrCreateFolderInfo(folderId, "Folder");

    // the root folder has no parent
    if (info.isRootFolder())
    {
        throw new CmisInvalidArgumentException("Root folder has no parent!");
    }

    // get the parent
    List<CMISNodeInfo> parentInfos = info.getParents();
    if (parentInfos.isEmpty())
    {
        throw new CmisRuntimeException("Folder has no parent and is not the root folder?!");
    }

    CMISNodeInfo parentInfo = addNodeInfo(parentInfos.get(0));

    ObjectData result = connector.createCMISObject(
            parentInfo, filter, false, IncludeRelationships.NONE,
            CMISConnector.RENDITION_NONE, false, false);
	boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
    if (isObjectInfoRequired)
    {
        getObjectInfo(
                repositoryId,
                parentInfo.getObjectId(),
                IncludeRelationships.NONE);
    }

    return result;
}
 
Example 21
@Override
public void updateProperties(
        String repositoryId, Holder<String> objectId, Holder<String> changeToken,
        final Properties properties, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    final CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");

    if (info.isVariant(CMISObjectVariant.ASSOC))
    {
        throw new CmisInvalidArgumentException("Relationship properties cannot be updated!");
    }
    else
    {
        if (info.isVariant(CMISObjectVariant.VERSION))
        {
            throw new CmisInvalidArgumentException("Document is not the latest version!");
        }

        final NodeRef nodeRef = info.getNodeRef();

        connector.setProperties(nodeRef, info.getType(), properties, new String[0]);
        
        objectId.setValue(connector.createObjectId(nodeRef));

    	boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
        if (isObjectInfoRequired)
        {
            getObjectInfo(repositoryId, objectId.getValue(), "*", IncludeRelationships.NONE);
        }

        connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
    }
}
 
Example 22
@Override
public FailedToDeleteData deleteTree(
        String repositoryId, String folderId, Boolean allVersions,
        UnfileObject unfileObjects, final Boolean continueOnFailure, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    if (!allVersions)
    {
        throw new CmisInvalidArgumentException("Only allVersions=true supported!");
    }

    if (unfileObjects == UnfileObject.UNFILE)
    {
        throw new CmisInvalidArgumentException("Unfiling not supported!");
    }

    final NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
    final FailedToDeleteDataImpl result = new FailedToDeleteDataImpl();

    try
    {
        connector.deleteNode(folderNodeRef, true);
    }
    catch (Exception e)
    {
        List<String> ids = new ArrayList<String>();
        ids.add(folderId);
        result.setIds(ids);
    }

    return result;
}
 
Example 23
@Override
public void checkOut(
        String repositoryId, final Holder<String> objectId, ExtensionsData extension,
        final Holder<Boolean> contentCopied)
{
    checkRepositoryId(repositoryId);

    CMISNodeInfo info = getOrCreateNodeInfo(objectId.getValue(), "Object");

    // Check for current version
    if (info.isVariant(CMISObjectVariant.CURRENT_VERSION))
    {
        // Good
    }
    else if (info.isVariant(CMISObjectVariant.VERSION))
    {
        throw new CmisInvalidArgumentException("Can't check out an old version of a document");
    }
    else {   
        throw new CmisInvalidArgumentException("Only documents can be checked out! Object was a " + info.getObjectVariant().toString());
    }

    // get object
    final NodeRef nodeRef = info.getNodeRef();

    if (!((DocumentTypeDefinition) info.getType().getTypeDefinition(false)).isVersionable())
    {
        throw new CmisConstraintException("Document is not versionable!");
    }
    
    // check out
    NodeRef pwcNodeRef = connector.getCheckOutCheckInService().checkout(nodeRef);
    CMISNodeInfo pwcNodeInfo = createNodeInfo(pwcNodeRef);
    objectId.setValue(pwcNodeInfo.getObjectId());

    if (contentCopied != null)
    {
        contentCopied.setValue(connector.getFileFolderService().getReader(pwcNodeRef) != null);
    }
}
 
Example 24
@Override
public void addObjectToFolder(
        String repositoryId, String objectId, String folderId, Boolean allVersions,
        ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    if (!allVersions)
    {
        throw new CmisInvalidArgumentException("Only allVersions=true supported!");
    }

    // get node ref
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");

    if (!info.isDocument())
    {
        throw new CmisInvalidArgumentException("Object is not a document!");
    }

    final NodeRef nodeRef = info.getNodeRef();

    // get the folder node ref
    final CMISNodeInfo folderInfo = getOrCreateFolderInfo(folderId, "Folder");

    connector.checkChildObjectType(folderInfo, info.getType().getTypeId());

    final QName name = QName.createQName(
            NamespaceService.CONTENT_MODEL_1_0_URI,
            QName.createValidLocalName((String) connector.getNodeService().getProperty(nodeRef,
                    ContentModel.PROP_NAME)));

    connector.getNodeService().addChild(
            folderInfo.getNodeRef(), nodeRef, ContentModel.ASSOC_CONTAINS, name);
}
 
Example 25
@Override
public void removeObjectFromFolder(String repositoryId, String objectId, String folderId, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    // get node ref
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");

    if (!info.isDocument())
    {
        throw new CmisInvalidArgumentException("Object is not a document!");
    }

    final NodeRef nodeRef = info.getNodeRef();

    // get the folder node ref
    final NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();

    // check primary parent
    if (connector.getNodeService().getPrimaryParent(nodeRef).getParentRef().equals(folderNodeRef))
    {
        throw new CmisConstraintException(
                "Unfiling from primary parent folder is not supported! Use deleteObject() instead.");
    }

    connector.getNodeService().removeChild(folderNodeRef, nodeRef);
}
 
Example 26
/**
 * Throws an exception if the given id is {@code null} or empty.
 */
protected void checkId(String name, String id) {
    if (id == null) {
        throw new CmisInvalidArgumentException(name + " must be set!");
    }

    if (id.length() == 0) {
        throw new CmisInvalidArgumentException(name + " must not be empty!");
    }
}
 
Example 27
/**
 * Throws an exception if the given ids are all {@code null} or empty.
 */
protected void checkIds(String name, String... ids) {
    for (String id : ids) {
        if (id != null && id.length() > 0) {
            return;
        }
    }

    throw new CmisInvalidArgumentException(name + " must be set!");
}
 
Example 28
/**
 * Throws an exception if the given holder or id is {@code null} or empty.
 */
protected void checkHolderId(String name, Holder<String> holder) {
    if (holder == null) {
        throw new CmisInvalidArgumentException(name + " must be set!");
    }

    checkId(name, holder.getValue());
}
 
Example 29
/**
 * Throws an exception if the given path is {@code null} or invalid.
 */
protected void checkPath(String name, String path) {
    if (path == null) {
        throw new CmisInvalidArgumentException(name + " must be set!");
    }

    if (path.length() == 0) {
        throw new CmisInvalidArgumentException(name + " must not be empty!");
    }

    if (path.charAt(0) != '/') {
        throw new CmisInvalidArgumentException(name + " must start with '/'!");
    }
}
 
Example 30
/**
 * Throws an exception if the given query statement is {@code null} or
 * empty.
 */
protected void checkQueryStatement(String statement) {
    if (statement == null) {
        throw new CmisInvalidArgumentException("Statement must be set!");
    }

    if (statement.length() == 0) {
        throw new CmisInvalidArgumentException("Statement must not be empty!");
    }
}