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
}
}
}
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;
}
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;
*/
}
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;
}
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));
}
}
Aggregations