Search in sources :

Example 21 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project alfresco-repository by Alfresco.

the class ConformanceCmisServiceWrapper method checkProperty.

/**
 * 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!");
    }
}
Also used : CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) UnfileObject(org.apache.chemistry.opencmis.commons.enums.UnfileObject)

Example 22 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project copper-cms by PogeyanOSS.

the class ObjectActor method getObject.

private JSONObject getObject(QueryGetRequest t) throws CmisInvalidArgumentException, IllegalArgumentException, CmisRuntimeException, CmisObjectNotFoundException {
    String permission = t.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(t.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = t.getObjectId();
    boolean acessPermission = false;
    IBaseObject data = DBUtils.BaseDAO.getByObjectId(t.getRepositoryId(), objectId, null);
    acessPermission = CmisObjectService.Impl.getAclAccess(t.getRepositoryId(), data, t.getUserObject());
    if (data != null && !data.getName().equals(ROOT) && acessPermission == false) {
        throw new CmisInvalidArgumentException("{} does not have valid acces control permission to access this object", t.getUserName());
    }
    ReturnVersion returnVersion = t.getEnumParameter(QueryGetRequest.PARAM_RETURN_VERSION, ReturnVersion.class);
    String filter = t.getParameter(QueryGetRequest.PARAM_FILTER);
    Boolean includeAllowableActions = t.getBooleanParameter(QueryGetRequest.PARAM_ALLOWABLE_ACTIONS);
    IncludeRelationships includeRelationships = t.getEnumParameter(QueryGetRequest.PARAM_RELATIONSHIPS, IncludeRelationships.class);
    String renditionFilter = t.getParameter(QueryGetRequest.PARAM_RENDITION_FILTER);
    Boolean includePolicyIds = t.getBooleanParameter(QueryGetRequest.PARAM_POLICY_IDS);
    Boolean includeAcl = t.getBooleanParameter(QueryGetRequest.PARAM_ACL);
    boolean succinct = t.getBooleanParameter(QueryGetRequest.PARAM_SUCCINCT, false);
    DateTimeFormat dateTimeFormat = t.getDateTimeFormatParameter();
    ObjectData object = null;
    if (returnVersion == ReturnVersion.LATEST || returnVersion == ReturnVersion.LASTESTMAJOR) {
        object = CmisVersioningServices.Impl.getObjectOfLatestVersion(t.getRepositoryId(), objectId, null, returnVersion == ReturnVersion.LASTESTMAJOR, filter, includeAllowableActions, null, includePolicyIds, includeAcl, null, null, t.getUserObject().getUserDN());
    } else {
        object = CmisObjectService.Impl.getObject(t.getRepositoryId(), objectId, filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds, includeAcl, null, t.getUserObject().getUserDN(), t.getBaseTypeId());
    }
    JSONObject result = JSONConverter.convert(object, CmisTypeCacheService.get(t.getRepositoryId()), JSONConverter.PropertyMode.OBJECT, succinct, dateTimeFormat);
    return result;
}
Also used : ReturnVersion(org.apache.chemistry.opencmis.commons.impl.ReturnVersion) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) IncludeRelationships(org.apache.chemistry.opencmis.commons.enums.IncludeRelationships) IBaseObject(com.pogeyan.cmis.api.data.IBaseObject) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)

Example 23 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project copper-cms by PogeyanOSS.

the class RepositoryActor method createType.

private JSONObject createType(PostRequest request) throws IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    if (typeStr == null) {
        throw new CmisInvalidArgumentException("Type definition missing!");
    }
    // convert type definition
    JSONParser parser = new JSONParser();
    Object typeJson = null;
    try {
        typeJson = parser.parse(typeStr);
    } catch (JSONParseException e) {
        LOG.error("JSON Parser error: {}", ExceptionUtils.getStackTrace(e));
    }
    if (!(typeJson instanceof Map)) {
        throw new CmisInvalidArgumentException("Invalid type definition!");
    }
    @SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
    TypeDefinition typeOut = CmisTypeServices.Impl.createType(request.getRepositoryId(), typeIn, null, request.getUserName());
    JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
    return jsonType;
}
Also used : JSONParseException(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONParser(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 24 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project copper-cms by PogeyanOSS.

the class RepositoryActor method updateType.

private JSONObject updateType(PostRequest request) throws CmisInvalidArgumentException, IllegalArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
    DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
    if (typeStr == null) {
        throw new CmisInvalidArgumentException("Type definition missing!");
    }
    // convert type definition
    JSONParser parser = new JSONParser();
    Object typeJson = null;
    try {
        typeJson = parser.parse(typeStr);
    } catch (JSONParseException e) {
        LOG.error("JSON parse exception: {}", ExceptionUtils.getStackTrace(e));
    }
    if (!(typeJson instanceof Map)) {
        throw new CmisInvalidArgumentException("Invalid type definition!");
    }
    @SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
    TypeDefinition typeOut = CmisTypeServices.Impl.updateType(request.getRepositoryId(), typeIn, null);
    JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
    return jsonType;
}
Also used : JSONParseException(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONParser(org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser) JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) DateTimeFormat(org.apache.chemistry.opencmis.commons.enums.DateTimeFormat) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)

Example 25 with CmisInvalidArgumentException

use of org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException in project copper-cms by PogeyanOSS.

the class ServletHelpers method writeJSON.

static void writeJSON(JSONStreamAware json, HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType(BrowserConstants.JSON_MIME_TYPE);
    response.setCharacterEncoding(IOUtils.UTF8);
    PrintWriter pw = response.getWriter();
    String callback = HttpUtils.getStringParameter(request, BrowserConstants.PARAM_CALLBACK);
    if (callback != null) {
        if (!callback.matches("[A-Za-z0-9._\\[\\]]*")) {
            throw new CmisInvalidArgumentException("Invalid callback name!");
        }
        pw.print(callback + "(");
    }
    json.writeJSONString(pw);
    if (callback != null) {
        pw.print(");");
    }
    pw.flush();
}
Also used : CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PrintWriter(java.io.PrintWriter)

Aggregations

CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)42 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)12 ArrayList (java.util.ArrayList)11 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)10 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)9 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)8 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)6 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)6 CmisStreamNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisStreamNotSupportedException)6 List (java.util.List)5 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)5 CmisContentAlreadyExistsException (org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException)5 IOException (java.io.IOException)4 QName (org.alfresco.service.namespace.QName)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4