Search in sources :

Example 1 with StringListApiResponse

use of org.entando.entando.aps.system.services.api.model.StringListApiResponse in project entando-core by entando.

the class ApiDataObjectModelInterface method getModels.

public StringListApiResponse getModels(Properties properties) throws ApiException, Throwable {
    StringListApiResponse response = new StringListApiResponse();
    try {
        List<DataObjectModel> models = null;
        String dataTypeParam = properties.getProperty("dataType");
        String dataType = (null != dataTypeParam && dataTypeParam.trim().length() > 0) ? dataTypeParam.trim() : null;
        if (null != dataType && null == this.getDataObjectManager().getSmallDataTypesMap().get(dataType)) {
            ApiError error = new ApiError(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Content Type " + dataType + " does not exist", Response.Status.CONFLICT);
            response.addError(error);
            dataType = null;
        }
        if (null != dataType) {
            models = this.getDataObjectModelManager().getModelsForDataObjectType(dataType);
        } else {
            models = this.getDataObjectModelManager().getDataObjectModels();
        }
        List<String> list = new ArrayList<String>();
        if (null != models) {
            for (int i = 0; i < models.size(); i++) {
                DataObjectModel model = models.get(i);
                list.add(String.valueOf(model.getId()));
            }
        }
        response.setResult(list, null);
    } catch (Throwable t) {
        _logger.error("Error loading models", t);
        throw new ApsSystemException("Error loading models", t);
    }
    return response;
}
Also used : StringListApiResponse(org.entando.entando.aps.system.services.api.model.StringListApiResponse) ArrayList(java.util.ArrayList) DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 2 with StringListApiResponse

use of org.entando.entando.aps.system.services.api.model.StringListApiResponse in project entando-core by entando.

the class ApiEntityTypeInterface method getEntityTypes.

public StringListApiResponse getEntityTypes(Properties properties) throws Throwable {
    StringListApiResponse response = new StringListApiResponse();
    try {
        IEntityManager manager = this.getEntityManager();
        Map<String, IApsEntity> prototypes = manager.getEntityPrototypes();
        List<String> codes = new ArrayList<String>();
        codes.addAll(prototypes.keySet());
        Collections.sort(codes);
        response.setResult(codes, null);
    } catch (Throwable t) {
        _logger.error("Error extracting entity type codes", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityTypes");
        throw new ApsSystemException("Error extracting entity type codes", t);
    }
    return response;
}
Also used : StringListApiResponse(org.entando.entando.aps.system.services.api.model.StringListApiResponse) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 3 with StringListApiResponse

use of org.entando.entando.aps.system.services.api.model.StringListApiResponse in project entando-core by entando.

the class ApiContentModelInterface method getModels.

public StringListApiResponse getModels(Properties properties) throws ApiException, Throwable {
    StringListApiResponse response = new StringListApiResponse();
    try {
        List<ContentModel> models = null;
        String contentTypeParam = properties.getProperty("contentType");
        String contentType = (null != contentTypeParam && contentTypeParam.trim().length() > 0) ? contentTypeParam.trim() : null;
        if (null != contentType && null == this.getContentManager().getSmallContentTypesMap().get(contentType)) {
            ApiError error = new ApiError(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Content Type " + contentType + " does not exist", Response.Status.CONFLICT);
            response.addError(error);
            contentType = null;
        }
        if (null != contentType) {
            models = this.getContentModelManager().getModelsForContentType(contentType);
        } else {
            models = this.getContentModelManager().getContentModels();
        }
        List<String> list = new ArrayList<String>();
        if (null != models) {
            for (int i = 0; i < models.size(); i++) {
                ContentModel model = models.get(i);
                list.add(String.valueOf(model.getId()));
            }
        }
        response.setResult(list, null);
    } catch (Throwable t) {
        _logger.error("Error loading models", t);
        // ApsSystemUtils.logThrowable(t, this, "getModels");
        throw new ApsSystemException("Error loading models", t);
    }
    return response;
}
Also used : ContentModel(com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel) StringListApiResponse(org.entando.entando.aps.system.services.api.model.StringListApiResponse) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 ArrayList (java.util.ArrayList)3 StringListApiResponse (org.entando.entando.aps.system.services.api.model.StringListApiResponse)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1 ContentModel (com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel)1 DataObjectModel (org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel)1