Search in sources :

Example 71 with ApiException

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

the class ApiI18nLabelInterface method deleteLabel.

public void deleteLabel(Properties properties) throws ApsSystemException, ApiException {
    try {
        String key = properties.getProperty("key");
        ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
        if (null == labelGroups) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
        }
        this.getI18nManager().deleteLabelGroup(key);
    } catch (ApiException | ApsSystemException ae) {
        _logger.error("Error deleting label", ae);
        throw new ApsSystemException("Error deleting labels", ae);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 72 with ApiException

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

the class ApiPageModelInterface method deletePageModel.

public void deletePageModel(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    try {
        PageModel pageModel = this.getPageModelManager().getPageModel(code);
        if (null == pageModel) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "PageModel with code '" + code + "' does not exist", Response.Status.CONFLICT);
        }
        Map<String, List<Object>> references = new HashMap<String, List<Object>>();
        ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
        String[] defNames = factory.getBeanNamesForType(PageModelUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = this.getBeanFactory().getBean(defNames[i]);
            } catch (Throwable t) {
                _logger.error("error extracting bean with name '{}'", defNames[i], t);
                throw new ApsSystemException("error extracting bean with name '" + defNames[i] + "'", t);
            }
            if (service != null) {
                PageModelUtilizer pageModelUtilizer = (PageModelUtilizer) service;
                List<Object> utilizers = pageModelUtilizer.getPageModelUtilizers(code);
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(pageModelUtilizer.getName(), utilizers);
                }
            }
        }
        if (!references.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "PageModel with code " + code + " has references with other object", Response.Status.CONFLICT);
        }
        this.getPageModelManager().deletePageModel(code);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting page model throw api", t);
        throw t;
    }
}
Also used : HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ArrayList(java.util.ArrayList) List(java.util.List) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 73 with ApiException

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

the class LocalStorageManagerInterface method getListDirectory.

public List<LinkedListItem> getListDirectory(Properties properties) throws Throwable {
    List<LinkedListItem> list = new ArrayList<LinkedListItem>();
    String pathValue = properties.getProperty(PARAM_PATH);
    String protectedValue = properties.getProperty(PARAM_IS_PROTECTED);
    boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true");
    try {
        if (StringUtils.isNotBlank(pathValue))
            pathValue = URLDecoder.decode(pathValue, "UTF-8");
        if (!StorageManagerUtil.isValidDirName(pathValue)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The path '" + pathValue + "' does not exists", Response.Status.CONFLICT);
        }
        BasicFileAttributeView[] files = this.getStorageManager().listAttributes(pathValue, isProtected);
        for (int i = 0; i < files.length; i++) {
            BasicFileAttributeView fileAttributeView = files[i];
            String url = this.getApiResourceURLWithParams(properties, fileAttributeView, pathValue, isProtected);
            LinkedListItem item = new LinkedListItem();
            item.setCode(this.buildResourcePath(fileAttributeView, pathValue));
            item.setUrl(url);
            list.add(item);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting storage resources in path: {} and protected flag: {} ", pathValue, isProtected, t);
        throw t;
    }
    return list;
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView) ArrayList(java.util.ArrayList) LinkedListItem(org.entando.entando.aps.system.services.api.model.LinkedListItem) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 74 with ApiException

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

the class ApiUserProfileInterface method getUserProfiles.

public List<String> getUserProfiles(Properties properties) throws Throwable {
    List<String> usernames = null;
    try {
        String userProfileType = properties.getProperty("typeCode");
        IUserProfile prototype = (IUserProfile) this.getUserProfileManager().getEntityPrototype(userProfileType);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile Type '" + userProfileType + "' does not exist", Response.Status.CONFLICT);
        }
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String filtersParam = properties.getProperty("filters");
        BaseFilterUtils filterUtils = new BaseFilterUtils();
        EntitySearchFilter[] filters = filterUtils.getFilters(prototype, filtersParam, langCode);
        usernames = this.getUserProfileManager().searchId(userProfileType, filters);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error searching usernames", t);
        // ApsSystemUtils.logThrowable(t, this, "getUserProfiles");
        throw new ApsSystemException("Error searching usernames", t);
    }
    return usernames;
}
Also used : BaseFilterUtils(com.agiletec.aps.system.common.entity.helper.BaseFilterUtils) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 75 with ApiException

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

the class ApiUserProfileInterface method deleteUserProfile.

public void deleteUserProfile(Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String username = properties.getProperty("username");
        IUserProfile userProfile = this.getUserProfileManager().getProfile(username);
        if (null == userProfile) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
        }
        this.getUserProfileManager().deleteProfile(username);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting user Profile", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteUserProfile");
        throw new ApsSystemException("Error deleting user Profile", t);
    }
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApiException (org.entando.entando.aps.system.services.api.model.ApiException)80 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)49 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)13 ApsProperties (com.agiletec.aps.util.ApsProperties)12 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)11 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)10 ArrayList (java.util.ArrayList)9 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)9 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)9 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)7 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)7 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)5 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)5 Properties (java.util.Properties)4