Search in sources :

Example 1 with CmisInvalidArgumentException

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

the class TestCMIS method testMNT12956QueryingCMIS11UsesDictionary11.

@Test
public void testMNT12956QueryingCMIS11UsesDictionary11() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person = network1.createUser(personInfo);
    String personId = person.getId();
    final List<NodeRef> documents = new ArrayList<NodeRef>();
    final String filename = GUID.generate();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            NodeRef docNodeRef = repoService.createDocument(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), filename, "test content");
            documents.add(docNodeRef);
            return null;
        }
    }, personId, network1.getId());
    NodeRef docNodeRef = documents.get(0);
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
    CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    CmisSession atomCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    // query
    {
        // searching by NodeRef, expect result objectIds to be objectId
        Set<String> expectedObjectIds = new HashSet<String>();
        expectedObjectIds.add(docNodeRef.getId());
        int numMatchingDocs = 0;
        // NodeRef input
        List<CMISNode> results = atomCmisSession11.query("SELECT cmis:objectId,cmis:name,cmis:secondaryObjectTypeIds FROM cmis:document WHERE cmis:name LIKE '" + filename + "'", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
        try {
            results = atomCmisSession10.query("SELECT cmis:objectId,cmis:name,cmis:secondaryObjectTypeIds FROM cmis:document WHERE cmis:name LIKE '" + filename + "'", false, 0, Integer.MAX_VALUE);
            fail("OpenCMIS 1.0 knows nothing about cmis:secondaryObjectTypeIds");
        } catch (CmisInvalidArgumentException expectedException) {
        // ok
        }
    }
}
Also used : CMISNode(org.alfresco.rest.api.tests.client.data.CMISNode) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) Set(java.util.Set) HashSet(java.util.HashSet) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ArrayList(java.util.ArrayList) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 2 with CmisInvalidArgumentException

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

the class ObjectActor method bulkUpdate.

private JSONArray bulkUpdate(PostRequest request) throws CmisInvalidArgumentException, CmisRuntimeException {
    // get object ids and change tokens
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "post")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken = new ArrayList<BulkUpdateObjectIdAndChangeToken>();
    List<String> objectIds = request.getObjectIds();
    List<String> changeTokens = request.getChangeTokens();
    if (CmisPropertyConverter.Impl.isNullOrEmpty(objectIds)) {
        throw new CmisInvalidArgumentException("No object ids provided!");
    }
    int n = objectIds.size();
    for (int i = 0; i < n; i++) {
        String id = objectIds.get(i);
        String changeToken = (changeTokens != null && changeTokens.size() > i ? changeTokens.get(i) : null);
        if (changeToken != null && changeToken.length() == 0) {
            changeToken = null;
        }
        objectIdAndChangeToken.add(new BulkUpdateObjectIdAndChangeTokenImpl(id, changeToken));
    }
    // get secondary type ids
    List<String> addSecondaryTypes = request.getAddSecondaryTypes();
    List<String> removeSecondaryTypes = request.getRemoveSecondaryTypes();
    Properties properties = CmisPropertyConverter.Impl.createUpdateProperties(request.getPropertyData(), null, addSecondaryTypes, objectIds, request.getRepositoryId(), null);
    List<BulkUpdateObjectIdAndChangeToken> result = CmisObjectService.Impl.bulkUpdateProperties(request.getRepositoryId(), objectIdAndChangeToken, properties, addSecondaryTypes, removeSecondaryTypes, null, request.getUserObject());
    // return result
    JSONArray jsonList = new JSONArray();
    if (result != null) {
        for (BulkUpdateObjectIdAndChangeToken oc : result) {
            if (oc != null) {
                jsonList.add(JSONConverter.convert(oc));
            }
        }
    }
    return jsonList;
}
Also used : BulkUpdateObjectIdAndChangeToken(org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) BulkUpdateObjectIdAndChangeTokenImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl) ArrayList(java.util.ArrayList) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) Properties(org.apache.chemistry.opencmis.commons.data.Properties)

Example 3 with CmisInvalidArgumentException

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

the class ObjectActor method getContent.

private PostFileResponse getContent(QueryGetRequest request) throws CmisObjectNotFoundException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    String streamId = request.getParameter(QueryGetRequest.PARAM_STREAM_ID);
    boolean download = false;
    String downloadParam = request.getParameter(QueryGetRequest.PARAM_DOWNLOAD);
    if (downloadParam != null && downloadParam.length() > 0) {
        String downloadParamLower = downloadParam.trim().toLowerCase(Locale.ENGLISH);
        if ("attachment".equals(downloadParamLower)) {
            download = true;
        } else if ("inline".equals(downloadParamLower)) {
            download = false;
        } else {
            throw new CmisInvalidArgumentException("Invalid download parameter value!");
        }
    }
    BigInteger offset = request.getOffset();
    BigInteger length = request.getLength();
    ContentStream content = CmisObjectService.Impl.getContentStream(request.getRepositoryId(), objectId, streamId, offset, length);
    PostFileResponse fileResponse = new PostFileResponse();
    fileResponse.setDownload(download);
    fileResponse.setOffset(offset);
    fileResponse.setContent(content);
    if (Helpers.isPerfMode()) {
        MetricsInputs.get().getCounter("Count_Downloads_" + request.getObjectId()).inc();
    }
    return fileResponse;
/*
		 * if (content == null || content.getStream() == null) { throw new
		 * CmisRuntimeException("Content stream is null!"); }
		 * 
		 * String contentType = content.getMimeType(); if (contentType == null) {
		 * contentType = QueryGetRequest.MEDIATYPE_OCTETSTREAM; }
		 * 
		 * String contentFilename = content.getFileName(); if (contentFilename == null)
		 * { contentFilename = "content"; }
		 * 
		 * // send content InputStream in = content.getStream(); OutputStream out =
		 * null; try { out = new FileOutputStream(content.getFileName());
		 * IOUtils.copy(in, out, QueryGetRequest.BUFFER_SIZE); out.flush(); } catch
		 * (Exception e) { LOG.error("writeContent exception: {}, {}", e.getMessage(),
		 * ExceptionUtils.getStackTrace(e)); throw new
		 * IllegalArgumentException("Could not write content: " + e.getMessage(), e); }
		 * finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } return null;
		 */
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) BigInteger(java.math.BigInteger) PostFileResponse(com.pogeyan.cmis.api.messages.PostFileResponse)

Example 4 with CmisInvalidArgumentException

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

the class ControlParser method getProperties.

public Map<String, List<String>> getProperties() {
    Map<Integer, String> propertyIds = oneDim.get(CONTROL_PROP_ID_LOWER);
    if (propertyIds == null) {
        return null;
    }
    Map<Integer, String> oneDimPropValues = oneDim.get(CONTROL_PROP_VALUE_LOWER);
    Map<Integer, Map<Integer, String>> twoDimPropValues = twoDim.get(CONTROL_PROP_VALUE_LOWER);
    int count = propertyIds.size();
    Map<String, List<String>> result = new LinkedHashMap<String, List<String>>();
    for (int i = 0; i < count; i++) {
        String propertyId = propertyIds.get(i);
        if (propertyId == null) {
            throw new CmisInvalidArgumentException(Constants.CONTROL_PROP_ID + " has gaps!");
        }
        List<String> values = null;
        if (oneDimPropValues != null && oneDimPropValues.containsKey(i)) {
            values = Collections.singletonList(oneDimPropValues.get(i));
        } else if (twoDimPropValues != null && twoDimPropValues.containsKey(i)) {
            values = new ArrayList<String>();
            Map<Integer, String> valuesMap = twoDimPropValues.get(i);
            if (valuesMap != null) {
                int valueCount = valuesMap.size();
                for (int j = 0; j < valueCount; j++) {
                    String value = valuesMap.get(j);
                    if (value == null) {
                        throw new CmisInvalidArgumentException(Constants.CONTROL_PROP_VALUE + "[" + i + "] has gaps!");
                    }
                    values.add(value);
                }
            }
        }
        result.put(propertyId, values);
    }
    return result;
}
Also used : CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with CmisInvalidArgumentException

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

the class LocalRepoDetails method setRepoStore.

@SuppressWarnings("unchecked")
public void setRepoStore() {
    JSONParser parser = new JSONParser();
    try {
        String envVariable = System.getenv("CMIS_REPO_JSON_LOCATION");
        if (envVariable == null) {
            LOG.error("CMIS_REPO_JSON_LOCATION not defined, unable to initialize CMIS");
            throw new CmisInvalidArgumentException("CMIS_REPO_JSON_LOCATION not defined, unable to initialize CMIS");
        }
        Object obj = parser.parse(new FileReader(envVariable));
        JSONArray repoArray = (JSONArray) obj;
        for (Object object : repoArray) {
            JSONObject jsonObject = (JSONObject) object;
            String repositoryId = (String) jsonObject.get("repositoryId");
            String repositoryName = (String) jsonObject.get("repositoryName");
            Map<String, String> DBName = (Map<String, String>) jsonObject.get("db");
            String description = (String) jsonObject.get("description");
            JSONObject fileObjects = (JSONObject) jsonObject.get("file");
            JSONArray objectFlowDetails = (JSONArray) fileObjects.get("object_flow");
            Map<String, String> fileDetails = (Map<String, String>) jsonObject.get("file");
            if (objectFlowDetails != null) {
                fileDetails.remove("object_flow");
                fileDetails.put("object_flow", objectFlowDetails.toString());
            }
            JSONObject loginObjects = (JSONObject) jsonObject.get("login");
            JSONArray loginDetails = (JSONArray) loginObjects.get("users");
            Map<String, String> loginRepo = (Map<String, String>) jsonObject.get("login");
            if (loginDetails != null) {
                loginRepo.remove("users");
                loginRepo.put("users", loginDetails.toString());
            }
            LocalRepo repo = new LocalRepo(repositoryId, repositoryName, DBName, description, fileDetails, loginRepo);
            repoStore.put(repositoryId, repo);
        }
    } catch (Exception e) {
        LOG.error("reading json file exception: {}", ExceptionUtils.getStackTrace(e));
    }
}
Also used : JSONObject(org.json.simple.JSONObject) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) Map(java.util.Map) HashMap(java.util.HashMap) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)

Aggregations

CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)17 ArrayList (java.util.ArrayList)5 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)5 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)5 Map (java.util.Map)4 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)4 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)3 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)3 JSONObject (org.apache.chemistry.opencmis.commons.impl.json.JSONObject)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)2 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)2 JSONParseException (org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException)2 JSONParser (org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser)2