Search in sources :

Example 76 with ApiException

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

the class ApiUserProfileInterface method updateUserProfile.

public StringApiResponse updateUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String username = jaxbUserProfile.getId();
        if (null == this.getUserProfileManager().getProfile(username)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
        }
        IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
        if (null == profilePrototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
        }
        IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
        List<ApiError> errors = this.validate(userProfile);
        if (errors.size() > 0) {
            response.addErrors(errors);
            response.setResult(IResponseBuilder.FAILURE, null);
            return response;
        }
        this.getUserProfileManager().updateProfile(username, userProfile);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating user profile", t);
        // ApsSystemUtils.logThrowable(t, this, "updateUserProfile");
        throw new ApsSystemException("Error updating user profile", t);
    }
    return response;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 77 with ApiException

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

the class ApiUserProfileTypeInterface method getUserProfileType.

public JAXBUserProfileType getUserProfileType(Properties properties) throws ApiException, Throwable {
    JAXBUserProfileType jaxbProfileType = null;
    try {
        String typeCode = properties.getProperty("typeCode");
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null == masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' does not exist");
        }
        jaxbProfileType = new JAXBUserProfileType(masterProfileType);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting user profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "getProfileType");
        throw new ApsSystemException("Error extracting user profile type", t);
    }
    return jaxbProfileType;
}
Also used : JAXBUserProfileType(org.entando.entando.aps.system.services.userprofile.api.model.JAXBUserProfileType) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 78 with ApiException

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

the class ApiUserProfileTypeInterface method deleteUserProfileType.

public void deleteUserProfileType(Properties properties) throws ApiException, Throwable {
    try {
        String typeCode = properties.getProperty("typeCode");
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null == masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' doesn't exist");
        }
        EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
        List<String> profileIds = this.getUserProfileManager().searchId(new EntitySearchFilter[] { filter });
        if (null != profileIds && !profileIds.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User profile type '" + typeCode + "' are used into " + profileIds.size() + " profiles");
        }
        ((IEntityTypesConfigurer) this.getUserProfileManager()).removeEntityPrototype(typeCode);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting user Profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteProfileType");
        throw new ApsSystemException("Error deleting user Profile type", t);
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 79 with ApiException

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

the class ApiServiceInterface method getServices.

public ArrayList<ServiceInfo> getServices(Properties properties) throws ApiException {
    ArrayList<ServiceInfo> services = new ArrayList<ServiceInfo>();
    try {
        String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String tagParamValue = properties.getProperty("tag");
        // String myentandoParamValue = properties.getProperty("myentando");
        // Boolean myentando = (null != myentandoParamValue && myentandoParamValue.trim().length() > 0) ? Boolean.valueOf(myentandoParamValue) : null;
        langCode = (null != langCode && null != this.getLangManager().getLang(langCode)) ? langCode : defaultLangCode;
        Map<String, ApiService> masterServices = this.getApiCatalogManager().getServices(tagParamValue);
        Iterator<ApiService> iter = masterServices.values().iterator();
        while (iter.hasNext()) {
            ApiService service = (ApiService) iter.next();
            if (service.isActive() && !service.isHidden() && this.checkServiceAuthorization(service, properties, false)) {
                ServiceInfo smallService = this.createServiceInfo(service, langCode, defaultLangCode);
                services.add(smallService);
            }
        }
        BeanComparator comparator = new BeanComparator("description");
        Collections.sort(services, comparator);
    } catch (Throwable t) {
        _logger.error("Error extracting services", t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
    }
    return services;
}
Also used : ServiceInfo(org.entando.entando.aps.system.services.api.model.ServiceInfo) ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 80 with ApiException

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

the class ApiEntityTypeInterface method deleteEntityType.

public void deleteEntityType(Properties properties) throws Throwable {
    try {
        String typeCode = properties.getProperty(this.getTypeCodeParamName());
        IApsEntity masterEntityType = this.getEntityManager().getEntityPrototype(typeCode);
        if (null == masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
        }
        EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
        List<String> entityIds = this.getEntityManager().searchId(new EntitySearchFilter[] { filter });
        if (null != entityIds && !entityIds.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " '" + typeCode + "' are used into " + entityIds.size() + " entities");
        }
        this.checkEntityTypeToDelete(masterEntityType);
        ((IEntityTypesConfigurer) this.getEntityManager()).removeEntityPrototype(typeCode);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting Entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteEntityType");
        throw new ApsSystemException("Error deleting Entity type", t);
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) 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