mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged DEV to HEAD
109455: Merged modules/custommodelmanagement/HEAD to DEV. 93923: SHA-300: Added ALFRESCO_MODEL_ADMINISTRATORS group. 95982: SHA-401: Implemented repo service for retrieving Custom Models. (WIP) 95983: SHA-400: Added Private REST API to retrieve custom model(s) - Get All models: http://localhost:8080/alfresco/api/-default-/private/alfresco/versions/1/cmm - Get the model: http://localhost:8080/alfresco/api/-default-/private/alfresco/versions/1/cmm/<model-name> 95984: SHA-401: Fixed the service to return null rather than throwing an exception, when the model does not exist. 96053: SHA-400: Modified the custom model API response to return the "status" as "ACTIVE" or "DRAFT". 96775: SHA-542: Added support to create a custom model. (WIP) 96779: SHA-543: Added Private REST API to create custom model(s). - SHA-539: Cleaned up test data. 96850: SHA-543: Added Author and Description properties to the custom model API. 97410: SHA-407, SHA-555: Added tests for custom model backend service and the related REST API. Also, a minor modification as a result of added tests. 97570: Modified the CMM REST API, per Kevin's request, to return empty arrays for model's types and aspects if they don't exist. 97731: SHA-386: Added support to activate custom models. Also, a minor modification to the backend service and REST API, based on the Alfresco REST API guidelines. 97775: SHA-386: Added tests for custom model activation (backend service). As well as, fixed the build failure by refactoring the public API tests. 97992: SHA-573, SHA-393, SHA-494: Added support to deactivate custom model, create a new type and create a new property group (aspect). 97994: Fixed the test as a result of renaming the service method. 98123: SHA-393, SHA-494: Enabled the CMM REST API to create/update Types and/or Aspects via PUT. Also added validations for aspect/type's name. 98259: SHA-453: Added backend and REST API support to delete a custom model. 98690: SHA-393, SHA-494, SHA-453, SHA-575: Added tests for custom model backend service and the related REST API. Also, a minor modification as a result of added tests. 99276: SHA-549: Added backend support to update a custom model. Also, refactored the service to externalise the error messages. - SHA-550: Added REST API support to update a custom model. - SHA-619: Made sure the backend service validates the model before creating a node. - SHA-623: Added checks to not allow a user to create a custom model with the same name as the bootstrapped models. 99287: SHA-619: Added InvalidCustomModelException for the CMM service to throw when the model validation fails. 99514: SHA-506: added backend and API support to create custom Type/Aspect properties. Also refactored the API to overcome the Public API limitations. 99522: SHA-506: Modified the Type/Aspect JSON payload to include a new read only property "prefixedName". 99527: Fixed Bamboo build failure as the result of r99522 commit. 99630: SHA-506: - Updated the API to exclude the inherited properties. - Added API tests for creating properties. - Modified the Custom Properties JSON response to include a new read only attribute "prefixedName". 99662: SHA-351: Updated the API to support 'mandatory' and 'mandatoryEnforced' properties. - SHA-410: Updated the API to support 'defaultValue' property. - SHA-506: Modified the Custom Properties JSON response to include 'description' and 'multiValued' attributes. 99669: SHA-506: Removed the unnecessary (at least in this sprint) methods from the backend service. 99684: SHA-638: Added checks to not allow a user to create a custom model with already in-use namespace prefix. 99959: SHA-679: Modified the custom model API to not import the already defined namespace. 100211: SHA-607: Modified the custom model API to support delete model's type. Also, removed the unnecessary test as we depend on the dictionary service, so no need to test it in the custom model API. 100281: Added Types and Aspects to the GET a single model API response, when it is requested with "?select=all" query string. 100335: Added test for "?select=all" query string within the GET a single model API (see rev 100281). 100366: SHA-612: Modified the custom model API to support delete model's aspect. 100738: SHA-698: Added checks so the model Admin is not allowed to deactivate a custom model when its types/aspects are parent to other models' types/aspects (regardless of the model being active or not). 100740: SHA-698: Fixed Bamboo build failures. 101085: SHA-703: Added dependency validation before deleting custom type/aspect in the custom model API. 101160: Modified the custom model API to return all properties (including the inherited properties) of the type/aspect, when requested by "?select=allProps". 101636: SHA-697. 101771: SHA-706: Made custom models hidden in the data dictionary. 101863: SHA-701: Added checks to not allow creating duplicate properties within the same model. Also, removed unnecessary/duplicate constants from the custom model service class. 101983: SHA-688: Fixed the error message by getting the root-cause-exception and returning its message. However, DictionaryException messages are not localised, so this will be fixed in the alfresco core. 102223: Fix for SHA-726: Not able to edit prefix field of deactivated model when model type is referenced within same model - The API will update the parent prefixed name with the new prefix. - Also, added more validations to the CMM API, when setting a type/asptect's parent. 102587: SHA-741, SHA-745, SHA-747: Added custom model Constraints support. 102725: SHA-784: Fixed parent validation of the type/aspect. 103030: SHA-741, SHA-745, SHA-747: Added tests for custom model Constraints. - Also fixed and refactored the API code as the result of tests. 103753: SHA-846: Added inline constraints support. Also: - Modified the backend CMM service to throw CustomModelConstraintException when the root cause is DuplicateDefinitionException. - Removed the duplicate name check from the CMM API, as now it will depend on the exceptions thrown upon model compilation. 103885: SHA-819, SHA-833: Added support to edit existing type/aspect. 103973: SHA-819, SHA-833: Added API tests for types/aspects Edit. Also, refactored CMM API tests by moving the tests to their corresponding test class. 104079: SHA-808: Fixed custom models bidirectional dependency. 104158: Deleted the ExtendedRepoAdminService class as the required functionality has been added (see SHA-879) to the core alfresco code. 104287: SHA-843: Modified the custom model API to support delete property. Also, minor refactoring of the API tests. 104403: SHA-842: Modified the custom model API to support Edit property. 104475: SHA-842: Added API tests for Edit property. 104569: SHA-913 - Remove case sensitive option from the UI - SHA-914 - Update PO and tests that use the case sensitive option - Remove case sensitive option on LIST constraint throughout Also: - Update Aikau version to 1.0.18 104690: Fixed Bamboo build failure caused by r104569. 104849: SHA-808: Fixed custom models circular dependencies. 105297: SHA-807: Added property default-value and constraint (REGEX, MINMAX and LENGTH) validators. 105642: SHA-950: Wrapped backend CMM service method with a NEW transaction, in order to catch the thrown exception within DictionaryModelTypeTransactionListener. Also refactored the CMM backend service tests as the result of this change. 106677: SHA-888, SHA-889, SHA-890: Added Backend and API support to export a custom model and its associated Share form. 106722: SHA-888, SHA-889, SHA-890: Fixed a few minor issues raised during code review. 107007: ACE-4019: Modified the CMM service to not start a new TX when creating a new model. 107070: Temporarily enabled (hard coded) index and facetable attributes in the custom model properties. 107296: GERMAN: Model Manager files localised as per EN-rev105921 107297: FRENCH: Model Manager localised files based on EN-rev105921 107315: SPANISH: Model Manager localised files based on EN-rev105921 107317: JAPANESE: Model Manager localised files based on EN-rev105921 107321: ITALIAN: Model Manager localised files based on EN-rev105921 107322: DUTCH: Model Manager localised files based on EN-rev105921 107335: SHA-889: Modified the CMM service to not throw an exception when exporting the model and its associated share extension module, where the Share extension module has not been created for the model yet. 107456: SHA-893: Added API support to upload/import a custom model and its associated Share extension module. 107560: SHA-893: Added model upload API tests as well as minor fixes. 107647: SHA-893: Fixed minor issues raised during code review. 107773: Docs review of message labels and errors. 107866: SHA-1126: Added check for the maximum value of the MINMAX constraint to be a positive nonzero value. 108117: SHA-832: Added validation for properties' default values to be checked against the property defined constraint. 108256: SHA-1194: Modified CMM API to support indexing options. 108510: SHA-1151: Externalised CMM rest API error messages. - SHA-1196: Changed the CMM Rest API input validator to use the same RegExs as the CMM Share. 108518: SHA-1194: Changed CMM property facetable options to include "UNSET". 108561: GERMAN: Model Manager files updated as per EN-rev107962 108562: FRENCH: Model Manager files updated as per EN-rev107962 108565: ITALIAN: Model Manager files updated as per EN-rev107962 108566: SPANISH: Model Manager files updated as per EN-rev107962 108567: JAPANESE: Model Manager files updated as per EN-rev107962 108568: NORWEGIAN Bokmal: Model Manager files updated as per EN-rev107962 108570: DUTCH: Model Manager files updated as per EN-rev107962 108571: RUSSIAN: Model Manager files updated as per EN-rev107962 108572: BRAZILIAN Portuguese: Model Manager files updated as per EN-rev107962 108573: SIMPLIFIED CHINESE: Model Manager files updated as per EN-rev107962 108604: Removed the unnecessary escaped quotation from the strings which don't have variables. 108721: Api message changes from docs. 108728: Changed "Property group" to "Aspect" in the CMM API error messages. 108934: Added the missing escaped quotation into API messages. 109037: Changes from docs for mandatory field character messages in the API. 109204: ITALIAN: Updated bundle based on EN rev109039 109205: GERMAN: Updated bundle based on EN rev109039 109206: FRENCH: Updated bundle based on EN rev109039 109223: GERMAN: Updated bundle based on EN rev109039 - fixed single quotes 109226: FRENCH: Updated bundle based on EN rev109039 - fixed single quotes 109228: ITALIAN: Updated bundle based on EN rev109039 - fixed single quotes 109230: FRENCH: Updated bundle based on EN rev109039 - fixed single quotes again 109235: JAPANESE: Updated bundle based on EN rev109039 109293: SPANISH: Updated bundle based on EN rev109039 109300: DUTCH: Updated bundle based on EN rev109039 109412: - Refactored the CMM JMX support to return CompositeData for performance reasons. - Reorganised a few of CMM classes/interfaces to make it easier for merging to alfresco core. - A minor fixes as a result of Find Bugs analysis. - Added the minimum and maximum repo versions for CMM module. 109421: NORWEGIAN: Updated bundle based on EN rev109039 109424: BRAZILIAN PORTUGUESE: Updated bundle based on EN rev109039 109426: RUSSIAN: Updated bundle based on EN rev109039 109427: CHINESE: Updated bundle based on EN rev10903 109475: Added CMM Model into the core services (missed from previous commit). 109480: SHA-723: Added custom models analytics in HeartBeat data. 109481: SHA-528: Added GROUP_ALFRESCO_MODEL_ADMINISTRATORS_AUTHORITY patch. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@109490 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.web.scripts.custommodel;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
||||
import org.alfresco.repo.dictionary.CustomModelServiceImpl;
|
||||
import org.alfresco.repo.dictionary.M2Model;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.api.CustomModels;
|
||||
import org.alfresco.rest.api.model.CustomModel;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.service.cmr.dictionary.CustomModelService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.XMLUtil;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.servlet.FormData;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Custom model upload POST. This class is the controller for the
|
||||
* "cmm-upload.post" web scripts.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomModelUploadPost extends DeclarativeWebScript
|
||||
{
|
||||
private static final String SHARE_EXT_MODULE_ROOT_ELEMENT = "module";
|
||||
private static final String TEMP_FILE_PREFIX = "cmmExport";
|
||||
private static final String TEMP_FILE_SUFFIX = ".zip";
|
||||
private static final int BUFFER_SIZE = 10 * 1024;
|
||||
|
||||
private CustomModels customModels;
|
||||
private CustomModelService customModelService;
|
||||
|
||||
public void setCustomModels(CustomModels customModels)
|
||||
{
|
||||
this.customModels = customModels;
|
||||
}
|
||||
|
||||
public void setCustomModelService(CustomModelService customModelService)
|
||||
{
|
||||
this.customModelService = customModelService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
if (!customModelService.isModelAdmin(AuthenticationUtil.getFullyAuthenticatedUser()))
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_FORBIDDEN, PermissionDeniedException.DEFAULT_MESSAGE_ID);
|
||||
}
|
||||
|
||||
FormData formData = (FormData) req.parseContent();
|
||||
if (formData == null || !formData.getIsMultiPart())
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_not_multi_part_req");
|
||||
}
|
||||
|
||||
ImportResult resultData = null;
|
||||
boolean processed = false;
|
||||
for (FormData.FormField field : formData.getFields())
|
||||
{
|
||||
if (field.getIsFile())
|
||||
{
|
||||
final String fileName = field.getFilename();
|
||||
File tempFile = createTempFile(field.getInputStream());
|
||||
try (ZipFile zipFile = new ZipFile(tempFile, StandardCharsets.UTF_8))
|
||||
{
|
||||
resultData = processUpload(zipFile, field.getFilename());
|
||||
}
|
||||
catch (ZipException ze)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_not_zip_format", new Object[] { fileName });
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_zip_file_failure", io);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// now the import is done, delete the temp file
|
||||
tempFile.delete();
|
||||
}
|
||||
processed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_no_zip_file_uploaded");
|
||||
}
|
||||
|
||||
// If we get here, then importing the custom model didn't throw any exceptions.
|
||||
Map<String, Object> model = new HashMap<>(2);
|
||||
model.put("importedModelName", resultData.getImportedModelName());
|
||||
model.put("shareExtXMLFragment", resultData.getShareExtXMLFragment());
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
protected File createTempFile(InputStream inputStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
File tempFile = TempFileProvider.createTempFile(inputStream, TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
|
||||
return tempFile;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_zip_file_failure", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected ImportResult processUpload(ZipFile zipFile, String filename) throws IOException
|
||||
{
|
||||
if (zipFile.size() > 2)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_package");
|
||||
}
|
||||
|
||||
CustomModel customModel = null;
|
||||
String shareExtModule = null;
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements())
|
||||
{
|
||||
ZipEntry entry = entries.nextElement();
|
||||
|
||||
if (!entry.isDirectory())
|
||||
{
|
||||
final String entryName = entry.getName();
|
||||
try (InputStream input = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE))
|
||||
{
|
||||
if (!(entryName.endsWith(CustomModelServiceImpl.SHARE_EXT_MODULE_SUFFIX)) && customModel == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
M2Model m2Model = M2Model.createModel(input);
|
||||
customModel = importModel(m2Model);
|
||||
}
|
||||
catch (DictionaryException ex)
|
||||
{
|
||||
if (shareExtModule == null)
|
||||
{
|
||||
// Get the input stream again, as the zip file doesn't support reset.
|
||||
try (InputStream moduleInputStream = new BufferedInputStream(zipFile.getInputStream(entry), BUFFER_SIZE))
|
||||
{
|
||||
shareExtModule = getExtensionModule(moduleInputStream, entryName);
|
||||
}
|
||||
|
||||
if (shareExtModule == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_zip_entry_format", new Object[] { entryName });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_model_entry", new Object[] { entryName });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shareExtModule = getExtensionModule(input, entryName);
|
||||
if (shareExtModule == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { entryName });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ImportResult(customModel, shareExtModule);
|
||||
}
|
||||
|
||||
protected CustomModel importModel(M2Model m2Model)
|
||||
{
|
||||
CustomModel model = null;
|
||||
try
|
||||
{
|
||||
model = customModels.createCustomModel(m2Model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
int statusCode;
|
||||
if (ex instanceof ConstraintViolatedException)
|
||||
{
|
||||
statusCode = Status.STATUS_CONFLICT;
|
||||
}
|
||||
else if (ex instanceof InvalidArgumentException)
|
||||
{
|
||||
statusCode = Status.STATUS_BAD_REQUEST;
|
||||
}
|
||||
else
|
||||
{
|
||||
statusCode = Status.STATUS_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
String msg = ex.getMessage();
|
||||
// remove log numbers. regEx => match 8 or more integers
|
||||
msg = (msg != null) ? msg.replaceAll("\\d{8,}", "").trim() : "cmm.rest_api.model.import_failure";
|
||||
|
||||
throw new WebScriptException(statusCode, msg);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
protected String getExtensionModule(InputStream inputStream, String fileName)
|
||||
{
|
||||
Element rootElement = null;
|
||||
try
|
||||
{
|
||||
final DocumentBuilder db = XMLUtil.getDocumentBuilder();
|
||||
rootElement = db.parse(inputStream).getDocumentElement();
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_ext_module_file_failure", io);
|
||||
}
|
||||
catch (SAXException ex)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { fileName }, ex);
|
||||
}
|
||||
|
||||
if (rootElement != null && SHARE_EXT_MODULE_ROOT_ELEMENT.equals(rootElement.getNodeName()))
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
XMLUtil.print(rootElement, sw, false);
|
||||
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple POJO for model import result.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public static class ImportResult
|
||||
{
|
||||
private String importedModelName;
|
||||
private String shareExtXMLFragment;
|
||||
|
||||
public ImportResult(CustomModel customModel, String shareExtXMLFragment)
|
||||
{
|
||||
this.shareExtXMLFragment = shareExtXMLFragment;
|
||||
if (customModel != null)
|
||||
{
|
||||
this.importedModelName = customModel.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public String getImportedModelName()
|
||||
{
|
||||
return this.importedModelName;
|
||||
}
|
||||
|
||||
public String getShareExtXMLFragment()
|
||||
{
|
||||
return this.shareExtXMLFragment;
|
||||
}
|
||||
}
|
||||
}
|
220
source/java/org/alfresco/rest/api/CustomModels.java
Normal file
220
source/java/org/alfresco/rest/api/CustomModels.java
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.repo.dictionary.M2Model;
|
||||
import org.alfresco.rest.api.model.CustomAspect;
|
||||
import org.alfresco.rest.api.model.CustomModel;
|
||||
import org.alfresco.rest.api.model.CustomModelConstraint;
|
||||
import org.alfresco.rest.api.model.CustomModelDownload;
|
||||
import org.alfresco.rest.api.model.CustomType;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public interface CustomModels
|
||||
{
|
||||
/**
|
||||
* Gets the {@code org.alfresco.rest.api.model.CustomModel} representation for the given model
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModel} object
|
||||
*/
|
||||
public CustomModel getCustomModel(String modelName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Gets a paged list of all custom models
|
||||
*
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return a paged list of {@code org.alfresco.rest.api.model.CustomModel} objects
|
||||
*/
|
||||
public CollectionWithPagingInfo<CustomModel> getCustomModels(Parameters parameters);
|
||||
|
||||
/**
|
||||
* Creates custom model
|
||||
*
|
||||
* @param model the custom model to create
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModel} object
|
||||
*/
|
||||
public CustomModel createCustomModel(CustomModel model);
|
||||
|
||||
/**
|
||||
* Creates custom model from the imported {@link M2Model}.
|
||||
*
|
||||
* @param m2Model the model
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModel} object
|
||||
*/
|
||||
public CustomModel createCustomModel(M2Model m2Model);
|
||||
|
||||
/**
|
||||
* Updates or activates/deactivates the custom model
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param model the custom model to update (JSON payload)
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModel} object
|
||||
*/
|
||||
public CustomModel updateCustomModel(String modelName, CustomModel model, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Deletes the custom model
|
||||
*
|
||||
* @param modelName the model name
|
||||
*/
|
||||
public void deleteCustomModel(String modelName);
|
||||
|
||||
/**
|
||||
* Gets the {@code org.alfresco.rest.api.model.CustomType} representation of
|
||||
* the given model's type
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param typeName the model's type name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomType} object
|
||||
*/
|
||||
public CustomType getCustomType(String modelName, String typeName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Gets a paged list of all the given custom model's types
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return a paged list of {@code org.alfresco.rest.api.model.CustomType} objects
|
||||
*/
|
||||
public CollectionWithPagingInfo<CustomType> getCustomTypes(String modelName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Creates custom model's type
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param type the custom type to create within the given model
|
||||
* @return {@code org.alfresco.rest.api.model.CustomType} object
|
||||
*/
|
||||
public CustomType createCustomType(String modelName, CustomType type);
|
||||
|
||||
/**
|
||||
* Updates the custom model's type
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param type the custom model's type to update (JSON payload)
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomType} object
|
||||
*/
|
||||
public CustomType updateCustomType(String modelName, CustomType type, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Deletes the custom model's type
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param typeName the model's type name
|
||||
*/
|
||||
public void deleteCustomType(String modelName, String typeName);
|
||||
|
||||
/**
|
||||
* Gets the {@code org.alfresco.rest.api.model.CustomAspect} representation of
|
||||
* the given model's aspect
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param aspectName the model's aspect name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomAspect} object
|
||||
*/
|
||||
public CustomAspect getCustomAspect(String modelName, String aspectName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Gets a paged list of all the given custom model's aspects
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return a paged list of {@code org.alfresco.rest.api.model.CustomAspect} objects
|
||||
*/
|
||||
public CollectionWithPagingInfo<CustomAspect> getCustomAspects(String modelName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Creates custom model's aspect
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param aspect the custom aspect to create within the given model
|
||||
* @return {@code org.alfresco.rest.api.model.CustomAspect} object
|
||||
*/
|
||||
public CustomAspect createCustomAspect(String modelName, CustomAspect aspect);
|
||||
|
||||
/**
|
||||
* Updates the custom model's aspect
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param aspect the custom model's aspect to update (JSON payload)
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomAspect} object
|
||||
*/
|
||||
public CustomAspect updateCustomAspect(String modelName, CustomAspect aspect, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Deletes the custom model's aspect
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param aspectName the model's aspect name
|
||||
*/
|
||||
public void deleteCustomAspect(String modelName, String aspectName);
|
||||
|
||||
/**
|
||||
* Gets the {@code org.alfresco.rest.api.model.CustomModelConstraint}
|
||||
* representation of the given model's constraint
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param constraintName the model's constraint name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModelConstraint} object
|
||||
*/
|
||||
public CustomModelConstraint getCustomModelConstraint(String modelName, String constraintName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Gets a paged list of all of the given custom model's constraints
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param parameters the {@link Parameters} object to get the parameters passed into the request
|
||||
* @return a paged list of {@code org.alfresco.rest.api.model.CustomModelConstraint} objects
|
||||
*/
|
||||
public CollectionWithPagingInfo<CustomModelConstraint> getCustomModelConstraints(String modelName, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Creates custom model's constraint
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param constraint the custom constraint to create within the given model
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModelConstraint} object
|
||||
*/
|
||||
public CustomModelConstraint createCustomModelConstraint(String modelName, CustomModelConstraint constraint);
|
||||
|
||||
/**
|
||||
* Starts the creation of a downloadable archive file containing the
|
||||
* custom model file and its associated Share extension module file (if requested).
|
||||
*
|
||||
* @param modelName the model name
|
||||
* @param parameters the {@link Parameters} object to get the parameters
|
||||
* passed into the request
|
||||
* @return {@code org.alfresco.rest.api.model.CustomModelDownload} object
|
||||
* containing the archive node reference
|
||||
*/
|
||||
public CustomModelDownload createDownload(String modelName, Parameters parameters);
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.cmm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.CustomModels;
|
||||
import org.alfresco.rest.api.model.CustomAspect;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@RelationshipResource(name = "aspects", entityResource = CustomModelEntityResource.class, title = "Custom Model Aspects")
|
||||
public class CustomModelAspectsRelation implements RelationshipResourceAction.Read<CustomAspect>,
|
||||
RelationshipResourceAction.ReadById<CustomAspect>,
|
||||
RelationshipResourceAction.Create<CustomAspect>,
|
||||
RelationshipResourceAction.Update<CustomAspect>,
|
||||
RelationshipResourceAction.Delete,
|
||||
InitializingBean
|
||||
{
|
||||
|
||||
private CustomModels customModels;
|
||||
|
||||
public void setCustomModels(CustomModels customModels)
|
||||
{
|
||||
this.customModels = customModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory(this, "customModels", customModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Returns a paged list of all the custom model's aspects.")
|
||||
public CollectionWithPagingInfo<CustomAspect> readAll(String modelName, Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomAspects(modelName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Returns custom aspect information for the given 'aspectName' in 'modelName'.")
|
||||
public CustomAspect readById(String modelName, String aspectName, Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomAspect(modelName, aspectName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Removes the custom aspect for the given 'aspectName' in 'modelName'.")
|
||||
public void delete(String modelName, String aspectName, Parameters parameters)
|
||||
{
|
||||
customModels.deleteCustomAspect(modelName, aspectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Updates the custom aspect in the given 'modelName'.")
|
||||
public CustomAspect update(String modelName, CustomAspect aspect, Parameters parameters)
|
||||
{
|
||||
return customModels.updateCustomAspect(modelName, aspect, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Creates custom aspects for the model 'modelName'.")
|
||||
public List<CustomAspect> create(String modelName, List<CustomAspect> aspects, Parameters parameters)
|
||||
{
|
||||
List<CustomAspect> result = new ArrayList<>(aspects.size());
|
||||
for (CustomAspect aspect : aspects)
|
||||
{
|
||||
result.add(customModels.createCustomAspect(modelName, aspect));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.cmm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.CustomModels;
|
||||
import org.alfresco.rest.api.model.CustomModelConstraint;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@RelationshipResource(name = "constraints", entityResource = CustomModelEntityResource.class, title = "Custom Model Constraints")
|
||||
public class CustomModelConstraintRelation implements RelationshipResourceAction.Read<CustomModelConstraint>,
|
||||
RelationshipResourceAction.ReadById<CustomModelConstraint>,
|
||||
RelationshipResourceAction.Create<CustomModelConstraint>,
|
||||
InitializingBean
|
||||
{
|
||||
|
||||
private CustomModels customModels;
|
||||
|
||||
public void setCustomModels(CustomModels customModels)
|
||||
{
|
||||
this.customModels = customModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory(this, "customModels", customModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Returns a paged list of all the custom model's constraints.")
|
||||
public CollectionWithPagingInfo<CustomModelConstraint> readAll(String modelName, Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomModelConstraints(modelName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Returns custom constraint information for the given 'constraintName' in 'modelName'.")
|
||||
public CustomModelConstraint readById(String modelName, String constraintName, Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomModelConstraint(modelName, constraintName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Creates custom constraints for the model 'modelName'.")
|
||||
public List<CustomModelConstraint> create(String modelName, List<CustomModelConstraint> constraints, Parameters parameters)
|
||||
{
|
||||
List<CustomModelConstraint> result = new ArrayList<>(constraints.size());
|
||||
for (CustomModelConstraint constraint : constraints)
|
||||
{
|
||||
result.add(customModels.createCustomModelConstraint(modelName, constraint));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.cmm;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.CustomModels;
|
||||
import org.alfresco.rest.api.model.CustomModelDownload;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@RelationshipResource(name = "download", entityResource = CustomModelEntityResource.class, title = "Custom Model Download")
|
||||
public class CustomModelDownloadRelation implements RelationshipResourceAction.Create<CustomModelDownload>, InitializingBean
|
||||
{
|
||||
|
||||
private CustomModels customModels;
|
||||
|
||||
public void setCustomModels(CustomModels customModels)
|
||||
{
|
||||
this.customModels = customModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory(this, "customModels", customModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Creates download node containing the custom model file and if specified, its associated Share extension module file.")
|
||||
public List<CustomModelDownload> create(String modelName, List<CustomModelDownload> download, Parameters parameters)
|
||||
{
|
||||
CustomModelDownload result = customModels.createDownload(modelName, parameters);
|
||||
return Collections.singletonList(result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.cmm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.CustomModels;
|
||||
import org.alfresco.rest.api.model.CustomModel;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.EntityResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@EntityResource(name = "cmm", title = "Custom Model Management")
|
||||
public class CustomModelEntityResource implements EntityResourceAction.Read<CustomModel>,
|
||||
EntityResourceAction.ReadById<CustomModel>,
|
||||
EntityResourceAction.Create<CustomModel>,
|
||||
EntityResourceAction.Update<CustomModel>,
|
||||
EntityResourceAction.Delete,
|
||||
InitializingBean
|
||||
{
|
||||
|
||||
private CustomModels customModels;
|
||||
|
||||
public void setCustomModels(CustomModels customModels)
|
||||
{
|
||||
this.customModels = customModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory(this, "customModels", customModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title="Returns custom model information for the given model name.")
|
||||
public CustomModel readById(String modelName, Parameters parameters) throws EntityNotFoundException
|
||||
{
|
||||
return customModels.getCustomModel(modelName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title="Returns a paged list of all custom models.")
|
||||
public CollectionWithPagingInfo<CustomModel> readAll(Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomModels(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title="Creates custom model(s).")
|
||||
public List<CustomModel> create(List<CustomModel> entity, Parameters parameters)
|
||||
{
|
||||
List<CustomModel> result = new ArrayList<>(entity.size());
|
||||
for (CustomModel cm : entity)
|
||||
{
|
||||
result.add(customModels.createCustomModel(cm));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Updates or activates/deactivates the custom model.")
|
||||
public CustomModel update(String modelName, CustomModel entity, Parameters parameters)
|
||||
{
|
||||
return customModels.updateCustomModel(modelName, entity, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Deletes the custom model.")
|
||||
public void delete(String modelName, Parameters parameters)
|
||||
{
|
||||
customModels.deleteCustomModel(modelName);
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.cmm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.CustomModels;
|
||||
import org.alfresco.rest.api.model.CustomType;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@RelationshipResource(name = "types", entityResource = CustomModelEntityResource.class, title = "Custom Model Types")
|
||||
public class CustomModelTypesRelation implements RelationshipResourceAction.Read<CustomType>,
|
||||
RelationshipResourceAction.ReadById<CustomType>,
|
||||
RelationshipResourceAction.Create<CustomType>,
|
||||
RelationshipResourceAction.Update<CustomType>,
|
||||
RelationshipResourceAction.Delete,
|
||||
InitializingBean
|
||||
{
|
||||
|
||||
private CustomModels customModels;
|
||||
|
||||
public void setCustomModels(CustomModels customModels)
|
||||
{
|
||||
this.customModels = customModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
PropertyCheck.mandatory(this, "customModels", customModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Returns a paged list of all the custom model's types.")
|
||||
public CollectionWithPagingInfo<CustomType> readAll(String modelName, Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomTypes(modelName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Returns custom type information for the given 'typeName' in 'modelName'.")
|
||||
public CustomType readById(String modelName, String typeName, Parameters parameters)
|
||||
{
|
||||
return customModels.getCustomType(modelName, typeName, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Removes the custom type for the given 'typeName' in 'modelName'.")
|
||||
public void delete(String modelName, String typeName, Parameters parameters)
|
||||
{
|
||||
customModels.deleteCustomType(modelName, typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Updates the custom type in the given 'modelName'.")
|
||||
public CustomType update(String modelName, CustomType type, Parameters parameters)
|
||||
{
|
||||
return customModels.updateCustomType(modelName, type, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Creates custom types for the model 'modelName'.")
|
||||
public List<CustomType> create(String modelName, List<CustomType> types, Parameters parameters)
|
||||
{
|
||||
List<CustomType> result = new ArrayList<>(types.size());
|
||||
for (CustomType type : types)
|
||||
{
|
||||
result.add(customModels.createCustomType(modelName, type));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
4
source/java/org/alfresco/rest/api/cmm/package-info.java
Normal file
4
source/java/org/alfresco/rest/api/cmm/package-info.java
Normal file
@@ -0,0 +1,4 @@
|
||||
@WebApi(name="alfresco", scope=Api.SCOPE.PRIVATE, version=1)
|
||||
package org.alfresco.rest.api.cmm;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.WebApi;
|
1718
source/java/org/alfresco/rest/api/impl/CustomModelsImpl.java
Normal file
1718
source/java/org/alfresco/rest/api/impl/CustomModelsImpl.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public abstract class AbstractClassModel extends AbstractCommonDetails
|
||||
{
|
||||
/* package */String parentName;
|
||||
/* package */List<CustomModelProperty> properties = Collections.emptyList();
|
||||
|
||||
public String getParentName()
|
||||
{
|
||||
return this.parentName;
|
||||
}
|
||||
|
||||
public void setParentName(String parentName)
|
||||
{
|
||||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
public List<CustomModelProperty> getProperties()
|
||||
{
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<CustomModelProperty> properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/* package */<T> List<T> setList(List<T> sourceList)
|
||||
{
|
||||
if (sourceList == null)
|
||||
{
|
||||
return Collections.<T> emptyList();
|
||||
}
|
||||
return new ArrayList<>(sourceList);
|
||||
}
|
||||
|
||||
/* package */String getParentNameAsString(QName parentQName)
|
||||
{
|
||||
if (parentQName != null)
|
||||
{
|
||||
return parentQName.toPrefixString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public abstract class AbstractCommonDetails implements Comparable<AbstractCommonDetails>
|
||||
{
|
||||
/* package */String name;
|
||||
/* package */String prefixedName;
|
||||
/* package */String title;
|
||||
/* package */String description;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPrefixedName()
|
||||
{
|
||||
return this.prefixedName;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof CustomModelConstraint))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CustomModelConstraint other = (CustomModelConstraint) obj;
|
||||
if (this.name == null)
|
||||
{
|
||||
if (other.name != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!this.name.equals(other.name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AbstractCommonDetails other)
|
||||
{
|
||||
return this.name.compareTo(other.getName());
|
||||
}
|
||||
}
|
60
source/java/org/alfresco/rest/api/model/CustomAspect.java
Normal file
60
source/java/org/alfresco/rest/api/model/CustomAspect.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomAspect extends AbstractClassModel
|
||||
{
|
||||
|
||||
public CustomAspect()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomAspect(AspectDefinition aspectDefinition, MessageLookup messageLookup, List<CustomModelProperty> properties)
|
||||
{
|
||||
this.name = aspectDefinition.getName().getLocalName();
|
||||
this.prefixedName = aspectDefinition.getName().toPrefixString();
|
||||
this.title = aspectDefinition.getTitle(messageLookup);
|
||||
this.description = aspectDefinition.getDescription(messageLookup);
|
||||
this.parentName = getParentNameAsString(aspectDefinition.getParentName());
|
||||
this.properties = setList(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(512);
|
||||
builder.append("CustomAspect [name=").append(this.name)
|
||||
.append(", prefixedName=").append(this.prefixedName)
|
||||
.append(", title=").append(this.title)
|
||||
.append(", description=").append(this.description)
|
||||
.append(", parentName=").append(parentName)
|
||||
.append(", properties=").append(properties)
|
||||
.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
217
source/java/org/alfresco/rest/api/model/CustomModel.java
Normal file
217
source/java/org/alfresco/rest/api/model/CustomModel.java
Normal file
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.CustomModelDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.NamespaceDefinition;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomModel implements Comparable<CustomModel>
|
||||
{
|
||||
public static enum ModelStatus
|
||||
{
|
||||
ACTIVE, DRAFT
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String author;
|
||||
private String description;
|
||||
private ModelStatus status;
|
||||
private String namespaceUri;
|
||||
private String namespacePrefix;
|
||||
private List<CustomType> types;
|
||||
private List<CustomAspect> aspects;
|
||||
private List<CustomModelConstraint> constraints;
|
||||
|
||||
public CustomModel()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomModel(CustomModelDefinition modelDefinition)
|
||||
{
|
||||
this(modelDefinition, null, null, null);
|
||||
}
|
||||
|
||||
public CustomModel(CustomModelDefinition modelDefinition, List<CustomType> types, List<CustomAspect> aspects, List<CustomModelConstraint> constraints)
|
||||
{
|
||||
this.name = modelDefinition.getName().getLocalName();
|
||||
this.author = modelDefinition.getAuthor();
|
||||
this.description = modelDefinition.getDescription();
|
||||
this.status = modelDefinition.isActive() ? ModelStatus.ACTIVE : ModelStatus.DRAFT;
|
||||
// we don't need to check for NoSuchElementException, as we don't allow
|
||||
// the model to be saved without a valid namespace
|
||||
NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next();
|
||||
this.namespaceUri = nsd.getUri();
|
||||
this.namespacePrefix = nsd.getPrefix();
|
||||
this.types = types;
|
||||
this.aspects = aspects;
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAuthor()
|
||||
{
|
||||
return this.author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author)
|
||||
{
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public ModelStatus getStatus()
|
||||
{
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(ModelStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getNamespaceUri()
|
||||
{
|
||||
return this.namespaceUri;
|
||||
}
|
||||
|
||||
public void setNamespaceUri(String namespaceUri)
|
||||
{
|
||||
this.namespaceUri = namespaceUri;
|
||||
}
|
||||
|
||||
public String getNamespacePrefix()
|
||||
{
|
||||
return this.namespacePrefix;
|
||||
}
|
||||
|
||||
public void setNamespacePrefix(String namespacePrefix)
|
||||
{
|
||||
this.namespacePrefix = namespacePrefix;
|
||||
}
|
||||
|
||||
public List<CustomType> getTypes()
|
||||
{
|
||||
return this.types;
|
||||
}
|
||||
|
||||
public void setTypes(List<CustomType> types)
|
||||
{
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public List<CustomAspect> getAspects()
|
||||
{
|
||||
return this.aspects;
|
||||
}
|
||||
|
||||
public void setAspects(List<CustomAspect> aspects)
|
||||
{
|
||||
this.aspects = aspects;
|
||||
}
|
||||
|
||||
public List<CustomModelConstraint> getConstraints()
|
||||
{
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
public void setConstraints(List<CustomModelConstraint> constraints)
|
||||
{
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof CustomModel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CustomModel other = (CustomModel) obj;
|
||||
if (this.name == null)
|
||||
{
|
||||
if (other.name != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!this.name.equals(other.name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CustomModel customModel)
|
||||
{
|
||||
return this.name.compareTo(customModel.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(512);
|
||||
builder.append("CustomModel [name=").append(this.name).append(", author=").append(this.author)
|
||||
.append(", description=").append(this.description).append(", status=").append(this.status)
|
||||
.append(", namespaceUri=").append(this.namespaceUri).append(", namespacePrefix=")
|
||||
.append(this.namespacePrefix).append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomModelConstraint extends AbstractCommonDetails
|
||||
{
|
||||
private String type;
|
||||
private List<CustomModelNamedValue> parameters = Collections.emptyList();
|
||||
|
||||
public CustomModelConstraint()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomModelConstraint(ConstraintDefinition constraintDefinition, MessageLookup messageLookup)
|
||||
{
|
||||
this.name = constraintDefinition.getName().getLocalName();
|
||||
this.prefixedName = constraintDefinition.getConstraint().getShortName();
|
||||
this.type = constraintDefinition.getConstraint().getType();
|
||||
this.title = constraintDefinition.getTitle(messageLookup);
|
||||
this.description = constraintDefinition.getDescription(messageLookup);
|
||||
this.parameters = convertToNamedValue(constraintDefinition.getConstraint().getParameters());
|
||||
}
|
||||
|
||||
private List<CustomModelNamedValue> convertToNamedValue(Map<String, Object> params)
|
||||
{
|
||||
List<CustomModelNamedValue> list = new ArrayList<>(params.size());
|
||||
for (Entry<String, Object> en : params.entrySet())
|
||||
{
|
||||
list.add(new CustomModelNamedValue(en.getKey(), en.getValue()));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<CustomModelNamedValue> getParameters()
|
||||
{
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
public void setParameters(List<CustomModelNamedValue> parameters)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(300);
|
||||
builder.append("CustomModelConstraint [name=").append(this.name)
|
||||
.append(", prefixedName=").append(this.prefixedName)
|
||||
.append(", type=").append(this.type)
|
||||
.append(", title=").append(this.title)
|
||||
.append(", description=").append(this.description)
|
||||
.append(", parameters=").append(this.parameters)
|
||||
.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomModelDownload implements Comparable<CustomModelDownload>
|
||||
{
|
||||
private String nodeRef;
|
||||
|
||||
public CustomModelDownload()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomModelDownload(NodeRef nodeRef)
|
||||
{
|
||||
this.nodeRef = nodeRef.toString();
|
||||
}
|
||||
|
||||
public String getNodeRef()
|
||||
{
|
||||
return this.nodeRef;
|
||||
}
|
||||
|
||||
public void setNodeRef(String nodeRef)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.nodeRef == null) ? 0 : this.nodeRef.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof CustomModelDownload))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CustomModelDownload other = (CustomModelDownload) obj;
|
||||
if (this.nodeRef == null)
|
||||
{
|
||||
if (other.nodeRef != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!this.nodeRef.equals(other.nodeRef))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CustomModelDownload other)
|
||||
{
|
||||
return this.nodeRef.toString().compareTo(other.getNodeRef().toString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomModelNamedValue implements Comparable<CustomModelNamedValue>
|
||||
{
|
||||
private String name;
|
||||
private String simpleValue = null;
|
||||
private List<String> listValue = null;
|
||||
|
||||
public CustomModelNamedValue()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomModelNamedValue(String name, Object value)
|
||||
{
|
||||
this.name = name;
|
||||
if (value instanceof List<?>)
|
||||
{
|
||||
List<?> values = (List<?>) value;
|
||||
listValue = new ArrayList<>(values.size());
|
||||
for(Object val : values)
|
||||
{
|
||||
listValue.add(convertToString(val));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
simpleValue = convertToString(value);
|
||||
}
|
||||
}
|
||||
|
||||
private String convertToString(Object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return DefaultTypeConverter.INSTANCE.convert(String.class, value);
|
||||
}
|
||||
catch (TypeConversionException e)
|
||||
{
|
||||
throw new InvalidArgumentException("Cannot convert to string '" + value + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSimpleValue()
|
||||
{
|
||||
return this.simpleValue;
|
||||
}
|
||||
|
||||
public void setSimpleValue(String simpleValue)
|
||||
{
|
||||
this.simpleValue = simpleValue;
|
||||
}
|
||||
|
||||
public List<String> getListValue()
|
||||
{
|
||||
return this.listValue;
|
||||
}
|
||||
|
||||
public void setListValue(List<String> listValue)
|
||||
{
|
||||
this.listValue = listValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof CustomModelNamedValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CustomModelNamedValue other = (CustomModelNamedValue) obj;
|
||||
if (this.name == null)
|
||||
{
|
||||
if (other.name != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!this.name.equals(other.name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CustomModelNamedValue other)
|
||||
{
|
||||
return name.compareTo(other.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(120);
|
||||
builder.append("CustomModelNamedValue [name=").append(this.name)
|
||||
.append(", simpleValue=").append(this.simpleValue)
|
||||
.append(", listValue=").append(this.listValue)
|
||||
.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
206
source/java/org/alfresco/rest/api/model/CustomModelProperty.java
Normal file
206
source/java/org/alfresco/rest/api/model/CustomModelProperty.java
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.dictionary.Facetable;
|
||||
import org.alfresco.repo.dictionary.IndexTokenisationMode;
|
||||
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomModelProperty extends AbstractCommonDetails
|
||||
{
|
||||
private String dataType;
|
||||
private boolean isMandatory;
|
||||
private boolean isMandatoryEnforced;
|
||||
private boolean isMultiValued;
|
||||
private String defaultValue;
|
||||
private boolean isIndexed = true;
|
||||
private Facetable facetable = Facetable.UNSET;
|
||||
private IndexTokenisationMode indexTokenisationMode;
|
||||
private List<String> constraintRefs = Collections.emptyList();
|
||||
private List<CustomModelConstraint> constraints = Collections.emptyList();
|
||||
|
||||
public CustomModelProperty()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomModelProperty(PropertyDefinition propertyDefinition, MessageLookup messageLookup)
|
||||
{
|
||||
this.name = propertyDefinition.getName().getLocalName();
|
||||
this.prefixedName = propertyDefinition.getName().toPrefixString();
|
||||
this.title = propertyDefinition.getTitle(messageLookup);
|
||||
this.dataType = propertyDefinition.getDataType().getName().toPrefixString();
|
||||
this.description = propertyDefinition.getDescription(messageLookup);
|
||||
this.isMandatory = propertyDefinition.isMandatory();
|
||||
this.isMandatoryEnforced = propertyDefinition.isMandatoryEnforced();
|
||||
this.isMultiValued = propertyDefinition.isMultiValued();
|
||||
this.defaultValue = propertyDefinition.getDefaultValue();
|
||||
this.isIndexed = propertyDefinition.isIndexed();
|
||||
this.facetable = propertyDefinition.getFacetable();
|
||||
this.indexTokenisationMode = propertyDefinition.getIndexTokenisationMode();
|
||||
List<ConstraintDefinition> constraintDefs = propertyDefinition.getConstraints();
|
||||
if (constraintDefs.size() > 0)
|
||||
{
|
||||
this.constraintRefs = new ArrayList<>();
|
||||
this.constraints = new ArrayList<>();
|
||||
for (ConstraintDefinition cd : constraintDefs)
|
||||
{
|
||||
if (cd.getRef() != null)
|
||||
{
|
||||
constraintRefs.add(cd.getRef().toPrefixString());
|
||||
}
|
||||
else
|
||||
{
|
||||
constraints.add(new CustomModelConstraint(cd, messageLookup));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDataType()
|
||||
{
|
||||
return this.dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType)
|
||||
{
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public boolean isMandatory()
|
||||
{
|
||||
return this.isMandatory;
|
||||
}
|
||||
|
||||
public void setMandatory(boolean isMandatory)
|
||||
{
|
||||
this.isMandatory = isMandatory;
|
||||
}
|
||||
|
||||
public boolean isMandatoryEnforced()
|
||||
{
|
||||
return this.isMandatoryEnforced;
|
||||
}
|
||||
|
||||
public void setMandatoryEnforced(boolean isMandatoryEnforced)
|
||||
{
|
||||
this.isMandatoryEnforced = isMandatoryEnforced;
|
||||
}
|
||||
|
||||
public boolean isMultiValued()
|
||||
{
|
||||
return this.isMultiValued;
|
||||
}
|
||||
|
||||
public void setMultiValued(boolean isMultiValued)
|
||||
{
|
||||
this.isMultiValued = isMultiValued;
|
||||
}
|
||||
|
||||
public String getDefaultValue()
|
||||
{
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(String defaultValue)
|
||||
{
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public boolean isIndexed()
|
||||
{
|
||||
return this.isIndexed;
|
||||
}
|
||||
|
||||
public void setIndexed(boolean isIndexed)
|
||||
{
|
||||
this.isIndexed = isIndexed;
|
||||
}
|
||||
|
||||
public Facetable getFacetable()
|
||||
{
|
||||
return this.facetable;
|
||||
}
|
||||
|
||||
public void setFacetable(Facetable facetable)
|
||||
{
|
||||
this.facetable = facetable;
|
||||
}
|
||||
|
||||
public IndexTokenisationMode getIndexTokenisationMode()
|
||||
{
|
||||
return this.indexTokenisationMode;
|
||||
}
|
||||
|
||||
public void setIndexTokenisationMode(IndexTokenisationMode indexTokenisationMode)
|
||||
{
|
||||
this.indexTokenisationMode = indexTokenisationMode;
|
||||
}
|
||||
|
||||
public List<String> getConstraintRefs()
|
||||
{
|
||||
return this.constraintRefs;
|
||||
}
|
||||
|
||||
public void setConstraintRefs(List<String> constraintRefs)
|
||||
{
|
||||
this.constraintRefs = constraintRefs;
|
||||
}
|
||||
|
||||
public List<CustomModelConstraint> getConstraints()
|
||||
{
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
public void setConstraints(List<CustomModelConstraint> constraints)
|
||||
{
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(612);
|
||||
builder.append("CustomModelProperty [name=").append(this.name)
|
||||
.append(", prefixedName=").append(this.prefixedName)
|
||||
.append(", title=").append(this.title)
|
||||
.append(", description=").append(this.description)
|
||||
.append(", dataType=").append(this.dataType)
|
||||
.append(", isMandatory=").append(this.isMandatory)
|
||||
.append(", isMandatoryEnforced=").append(this.isMandatoryEnforced)
|
||||
.append(", isMultiValued=").append(this.isMultiValued)
|
||||
.append(", defaultValue=").append(this.defaultValue)
|
||||
.append(", isIndexed=").append(this.isIndexed)
|
||||
.append(", facetable=").append(this.facetable)
|
||||
.append(", indexTokenisationMode=").append(this.indexTokenisationMode)
|
||||
.append(", constraintRefs=").append(this.constraintRefs)
|
||||
.append(", constraints=").append(this.constraints)
|
||||
.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
60
source/java/org/alfresco/rest/api/model/CustomType.java
Normal file
60
source/java/org/alfresco/rest/api/model/CustomType.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.i18n.MessageLookup;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class CustomType extends AbstractClassModel
|
||||
{
|
||||
|
||||
public CustomType()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomType(TypeDefinition typeDefinition, MessageLookup messageLookup, List<CustomModelProperty> properties)
|
||||
{
|
||||
this.name = typeDefinition.getName().getLocalName();
|
||||
this.prefixedName = typeDefinition.getName().toPrefixString();
|
||||
this.title = typeDefinition.getTitle(messageLookup);
|
||||
this.description = typeDefinition.getDescription(messageLookup);
|
||||
this.parentName = getParentNameAsString(typeDefinition.getParentName());
|
||||
this.properties = setList(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(512);
|
||||
builder.append("CustomType [name=").append(this.name)
|
||||
.append(", prefixedName=").append(this.prefixedName)
|
||||
.append(", title=").append(this.title)
|
||||
.append(", description=").append(this.description)
|
||||
.append(", parentName=").append(parentName)
|
||||
.append(", properties=").append(properties)
|
||||
.append(']');
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user