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!");
}
}
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;
}
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;
}
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;
}
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();
}
Aggregations