Search in sources :

Example 1 with BaseResourceDataBean

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean in project entando-core by entando.

the class ApiResourceInterface method addResource.

public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, true);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        String id = bean.getResourceId();
        if (null != id && id.trim().length() > 0) {
            Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
            Matcher matcher = pattern.matcher(id);
            if (!matcher.matches()) {
                throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
            }
        }
        this.getResourceManager().addResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in addResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : Pattern(java.util.regex.Pattern) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Matcher(java.util.regex.Matcher) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 2 with BaseResourceDataBean

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean in project entando-core by entando.

the class ApiResourceInterface method updateResource.

public StringApiResponse updateResource(JAXBResource jaxbResource, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, false);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        this.getResourceManager().updateResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (Throwable t) {
        _logger.error("error in updateResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse)

Example 3 with BaseResourceDataBean

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean in project entando-core by entando.

the class JAXBResource method createBataBean.

public BaseResourceDataBean createBataBean(ICategoryManager categoryManager) throws Throwable {
    BaseResourceDataBean bean = new BaseResourceDataBean();
    if (null != this.getCategories()) {
        List<Category> categories = new ArrayList<>();
        for (int i = 0; i < this.getCategories().size(); i++) {
            String categoryCode = this.getCategories().get(i);
            Category category = categoryManager.getCategory(categoryCode);
            if (null != category) {
                categories.add(category);
            }
        }
        bean.setCategories(categories);
    }
    bean.setDescr(this.getDescription());
    bean.setFileName(this.getFileName());
    bean.setMainGroup(this.getMainGroup());
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String mimeType = fileNameMap.getContentTypeFor(this.getFileName());
    bean.setMimeType(mimeType);
    bean.setResourceType(this.getTypeCode());
    bean.setResourceId(this.getId());
    if (null != this.getBase64()) {
        File file = this.byteArrayToFile();
        bean.setFile(file);
    }
    return bean;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ArrayList(java.util.ArrayList) FileNameMap(java.net.FileNameMap) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) File(java.io.File)

Aggregations

BaseResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)2 Category (com.agiletec.aps.system.services.category.Category)1 File (java.io.File)1 FileNameMap (java.net.FileNameMap)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1