/** * Converts FailedToDelete ids. */ public static JSONObject convert(final FailedToDeleteData ftd) { if (ftd == null) { return null; } JSONObject result = new JSONObject(); JSONArray ids = new JSONArray(); if (ftd.getIds() != null) { for (String id : ftd.getIds()) { ids.add(id); } } result.put(JSON_FAILEDTODELETE_ID, ids); convertExtension(ftd, result); return result; }
/** * Converts FailedToDelete ids. */ public static JSONObject convert(final FailedToDeleteData ftd) { if (ftd == null) { return null; } JSONObject result = new JSONObject(); JSONArray ids = new JSONArray(); if (ftd.getIds() != null) { for (String id : ftd.getIds()) { ids.add(id); } } result.put(JSON_FAILEDTODELETE_ID, ids); convertExtension(ftd, result); return result; }
private void printGroupResults(CmisTestGroup group, JSONArray jsonGroups) throws IOException { if (!group.isEnabled()) { return; } JSONObject jsonGroup = new JSONObject(); jsonGroups.add(jsonGroup); jsonGroup.put("name", group.getName()); if (group.getTests() != null && !group.getTests().isEmpty()) { JSONArray jsonTests = new JSONArray(); jsonGroup.put("tests", jsonTests); for (CmisTest test : group.getTests()) { printTestResults(test, jsonTests); } } }
private void printTestResults(CmisTest test, JSONArray jsonTests) throws IOException { if (!test.isEnabled()) { return; } JSONObject jsonTest = new JSONObject(); jsonTests.add(jsonTest); jsonTest.put("name", test.getName()); jsonTest.put("time", test.getTime()); if (test.getResults() != null && !test.getResults().isEmpty()) { JSONArray jsonResults = new JSONArray(); jsonTest.put("results", jsonResults); for (CmisTestResult result : test.getResults()) { printResult(result, jsonResults); } } }
private static void addExtensionToTarget(final CmisExtensionElement ext, final JSONObject target) { if (ext == null) { return; } Object value = null; if (isNotEmpty(ext.getChildren())) { value = convertExtensionList(ext.getChildren()); } else { value = ext.getValue(); } if (!target.containsKey(ext.getName())) { target.put(ext.getName(), value); } else { Object extValue = target.get(ext.getName()); JSONArray array; if (extValue instanceof JSONArray) { array = (JSONArray) extValue; } else { array = new JSONArray(); array.add(extValue); } array.add(value); target.put(ext.getName(), array); } }
private static void addExtensionToTarget(final CmisExtensionElement ext, final JSONObject target) { if (ext == null) { return; } Object value = null; if (isNotEmpty(ext.getChildren())) { value = convertExtensionList(ext.getChildren()); } else { value = ext.getValue(); } if (!target.containsKey(ext.getName())) { target.put(ext.getName(), value); } else { Object extValue = target.get(ext.getName()); JSONArray array; if (extValue instanceof JSONArray) { array = (JSONArray) extValue; } else { array = new JSONArray(); array.add(extValue); } array.add(value); target.put(ext.getName(), array); } }
TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service); for (ObjectData policy : policies) { jsonPolicies.add(JSONConverter.convert(policy, typeCache, JSONConverter.PropertyMode.OBJECT, succinct, dateTimeFormat));
/** * Converts a type definition container. */ public static JSONObject convert(final TypeDefinitionContainer container, final DateTimeFormat dateTimeFormat) { if (container == null) { return null; } JSONObject result = new JSONObject(); result.put(JSON_TYPESCONTAINER_TYPE, convert(container.getTypeDefinition(), dateTimeFormat)); if (isNotEmpty(container.getChildren())) { JSONArray children = new JSONArray(); for (TypeDefinitionContainer child : container.getChildren()) { children.add(convert(child, dateTimeFormat)); } result.put(JSON_TYPESCONTAINER_CHILDREN, children); } convertExtension(container, result); return result; }
/** * Converts a type definition list. */ public static JSONObject convert(final TypeDefinitionList list, final DateTimeFormat dateTimeFormat) { if (list == null) { return null; } JSONObject result = new JSONObject(); if (list.getList() != null) { JSONArray objects = new JSONArray(); for (TypeDefinition type : list.getList()) { objects.add(convert(type, dateTimeFormat)); } result.put(JSON_TYPESLIST_TYPES, objects); } setIfNotNull(JSON_TYPESLIST_HAS_MORE_ITEMS, list.hasMoreItems(), result); setIfNotNull(JSON_TYPESLIST_NUM_ITEMS, list.getNumItems(), result); convertExtension(list, result); return result; }
/** * Converts a type definition list. */ public static JSONObject convert(final TypeDefinitionList list, final DateTimeFormat dateTimeFormat) { if (list == null) { return null; } JSONObject result = new JSONObject(); if (list.getList() != null) { JSONArray objects = new JSONArray(); for (TypeDefinition type : list.getList()) { objects.add(convert(type, dateTimeFormat)); } result.put(JSON_TYPESLIST_TYPES, objects); } setIfNotNull(JSON_TYPESLIST_HAS_MORE_ITEMS, list.hasMoreItems(), result); setIfNotNull(JSON_TYPESLIST_NUM_ITEMS, list.getNumItems(), result); convertExtension(list, result); return result; }
/** * Converts a folder container. */ public static JSONObject convert(final ObjectInFolderContainer container, final TypeCache typeCache, final boolean succinct, final DateTimeFormat dateTimeFormat) { if (container == null) { return null; } JSONObject result = new JSONObject(); result.put(JSON_OBJECTINFOLDERCONTAINER_OBJECT, convert(container.getObject(), typeCache, succinct, dateTimeFormat)); if (isNotEmpty(container.getChildren())) { JSONArray children = new JSONArray(); for (ObjectInFolderContainer descendant : container.getChildren()) { children.add(JSONConverter.convert(descendant, typeCache, succinct, dateTimeFormat)); } result.put(JSON_OBJECTINFOLDERCONTAINER_CHILDREN, children); } convertExtension(container, result); return result; }
/** * Converts a folder container. */ public static JSONObject convert(final ObjectInFolderContainer container, final TypeCache typeCache, final boolean succinct, final DateTimeFormat dateTimeFormat) { if (container == null) { return null; } JSONObject result = new JSONObject(); result.put(JSON_OBJECTINFOLDERCONTAINER_OBJECT, convert(container.getObject(), typeCache, succinct, dateTimeFormat)); if (isNotEmpty(container.getChildren())) { JSONArray children = new JSONArray(); for (ObjectInFolderContainer descendant : container.getChildren()) { children.add(JSONConverter.convert(descendant, typeCache, succinct, dateTimeFormat)); } result.put(JSON_OBJECTINFOLDERCONTAINER_CHILDREN, children); } convertExtension(container, result); return result; }
/** * Sends a batch of new tokens. */ protected void sendTokens(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException { JSONArray result = new JSONArray(); if (!SimpleTokenHandlerSessionHelper.checkApplicationKey(request)) { // PARANOIA: remove the application key if the presented key is // wrong, don't allow a second attempt String appId = SimpleTokenHandlerSessionHelper.getApplicationIdFromKey(SimpleTokenHandlerSessionHelper .getKey(request)); if (appId != null) { SimpleTokenHandlerSessionHelper.removeApplicationKey(request, appId); } } else { // generate a batch of tokens String appId = SimpleTokenHandlerSessionHelper.getApplicationIdFromKey(SimpleTokenHandlerSessionHelper .getKey(request)); for (int i = 0; i < TOKEN_BATCH_SIZE; i++) { // create token String token = SimpleTokenHandlerSessionHelper.generateKey(appId); // put token into session and it to the response SimpleTokenHandlerSessionHelper.addToken(request, token); result.add(token); } } printJSON(response, result); }
/** * Converts a type definition container. */ public static JSONObject convert(final TypeDefinitionContainer container, final DateTimeFormat dateTimeFormat) { if (container == null) { return null; } JSONObject result = new JSONObject(); result.put(JSON_TYPESCONTAINER_TYPE, convert(container.getTypeDefinition(), dateTimeFormat)); if (isNotEmpty(container.getChildren())) { JSONArray children = new JSONArray(); for (TypeDefinitionContainer child : container.getChildren()) { children.add(convert(child, dateTimeFormat)); } result.put(JSON_TYPESCONTAINER_CHILDREN, children); } convertExtension(container, result); return result; }
/** * Converts a folder list. */ public static JSONObject convert(final ObjectInFolderList objectInFolderList, final TypeCache typeCache, final boolean succinct, final DateTimeFormat dateTimeFormat) { if (objectInFolderList == null) { return null; } JSONObject result = new JSONObject(); if (objectInFolderList.getObjects() != null) { JSONArray objects = new JSONArray(); for (ObjectInFolderData object : objectInFolderList.getObjects()) { objects.add(convert(object, typeCache, succinct, dateTimeFormat)); } result.put(JSON_OBJECTINFOLDERLIST_OBJECTS, objects); } setIfNotNull(JSON_OBJECTINFOLDERLIST_HAS_MORE_ITEMS, objectInFolderList.hasMoreItems(), result); setIfNotNull(JSON_OBJECTINFOLDERLIST_NUM_ITEMS, objectInFolderList.getNumItems(), result); convertExtension(objectInFolderList, result); return result; }
/** * Converts a folder list. */ public static JSONObject convert(final ObjectInFolderList objectInFolderList, final TypeCache typeCache, final boolean succinct, final DateTimeFormat dateTimeFormat) { if (objectInFolderList == null) { return null; } JSONObject result = new JSONObject(); if (objectInFolderList.getObjects() != null) { JSONArray objects = new JSONArray(); for (ObjectInFolderData object : objectInFolderList.getObjects()) { objects.add(convert(object, typeCache, succinct, dateTimeFormat)); } result.put(JSON_OBJECTINFOLDERLIST_OBJECTS, objects); } setIfNotNull(JSON_OBJECTINFOLDERLIST_HAS_MORE_ITEMS, objectInFolderList.hasMoreItems(), result); setIfNotNull(JSON_OBJECTINFOLDERLIST_NUM_ITEMS, objectInFolderList.getNumItems(), result); convertExtension(objectInFolderList, result); return result; }
/** * Converts a query object list. */ public static JSONObject convert(final ObjectList list, final TypeCache typeCache, final PropertyMode propertyMode, final boolean succinct, final DateTimeFormat dateTimeFormat) { if (list == null) { return null; } JSONObject result = new JSONObject(); JSONArray objects = new JSONArray(); if (list.getObjects() != null) { for (ObjectData object : list.getObjects()) { objects.add(convert(object, typeCache, propertyMode, succinct, dateTimeFormat)); } } if (propertyMode == PropertyMode.QUERY) { result.put(JSON_QUERYRESULTLIST_RESULTS, objects); setIfNotNull(JSON_QUERYRESULTLIST_HAS_MORE_ITEMS, list.hasMoreItems(), result); setIfNotNull(JSON_QUERYRESULTLIST_NUM_ITEMS, list.getNumItems(), result); } else { result.put(JSON_OBJECTLIST_OBJECTS, objects); setIfNotNull(JSON_OBJECTLIST_HAS_MORE_ITEMS, list.hasMoreItems(), result); setIfNotNull(JSON_OBJECTLIST_NUM_ITEMS, list.getNumItems(), result); } convertExtension(list, result); return result; }
/** * Converts a query object list. */ public static JSONObject convert(final ObjectList list, final TypeCache typeCache, final PropertyMode propertyMode, final boolean succinct, final DateTimeFormat dateTimeFormat) { if (list == null) { return null; } JSONObject result = new JSONObject(); JSONArray objects = new JSONArray(); if (list.getObjects() != null) { for (ObjectData object : list.getObjects()) { objects.add(convert(object, typeCache, propertyMode, succinct, dateTimeFormat)); } } if (propertyMode == PropertyMode.QUERY) { result.put(JSON_QUERYRESULTLIST_RESULTS, objects); setIfNotNull(JSON_QUERYRESULTLIST_HAS_MORE_ITEMS, list.hasMoreItems(), result); setIfNotNull(JSON_QUERYRESULTLIST_NUM_ITEMS, list.getNumItems(), result); } else { result.put(JSON_OBJECTLIST_OBJECTS, objects); setIfNotNull(JSON_OBJECTLIST_HAS_MORE_ITEMS, list.hasMoreItems(), result); setIfNotNull(JSON_OBJECTLIST_NUM_ITEMS, list.getNumItems(), result); } convertExtension(list, result); return result; }