Search in sources :

Example 76 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiUserProfileTypeInterface method updateUserProfileType.

public StringApiResponse updateUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbProfileType.getTypeCode();
        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");
        }
        Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
        IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
        ((IEntityTypesConfigurer) this.getUserProfileManager()).updateEntityPrototype(profileType);
        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 type", t);
        // ApsSystemUtils.logThrowable(t, this, "updateProfileType");
        throw new ApsSystemException("Error updating user profile type", t);
    }
    return response;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 77 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiUserProfileTypeInterface method addUserProfileType.

public StringApiResponse addUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbProfileType.getTypeCode();
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null != masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' already exists");
        }
        if (typeCode == null || typeCode.length() != 3) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
        }
        Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
        IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
        ((IEntityTypesConfigurer) this.getUserProfileManager()).addEntityPrototype(profileType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding user profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "addProfileType");
        throw new ApsSystemException("Error adding user profile type", t);
    }
    return response;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 78 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class WidgetService method removeWidget.

@Override
public void removeWidget(String widgetCode) {
    try {
        WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
        BeanPropertyBindingResult validationResult = checkWidgetForDelete(type);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetCode);
        for (String fragmentCode : fragmentCodes) {
            this.getGuiFragmentManager().deleteGuiFragment(fragmentCode);
        }
        this.getWidgetManager().deleteWidgetType(widgetCode);
    } catch (ApsSystemException e) {
        logger.error("Failed to remove widget type for request {} ", widgetCode);
        throw new RestServerError("failed to update widget type by code ", e);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 79 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ResponseBuilder method checkParameter.

private void checkParameter(ApiMethod apiMethod, Properties parameters) throws ApiException, Throwable {
    try {
        List<ApiMethodParameter> apiParameters = apiMethod.getParameters();
        if (null == apiParameters || apiParameters.isEmpty()) {
            return;
        }
        List<ApiError> errors = new ArrayList<ApiError>();
        for (int i = 0; i < apiParameters.size(); i++) {
            ApiMethodParameter apiParam = apiParameters.get(i);
            String paramName = apiParam.getKey();
            Object value = parameters.get(paramName);
            if (apiParam.isRequired() && (null == value || value.toString().trim().length() == 0)) {
                errors.add(new ApiError(IApiErrorCodes.API_PARAMETER_REQUIRED, "Parameter '" + paramName + "' is required", Response.Status.BAD_REQUEST));
            }
        }
        if (!errors.isEmpty()) {
            throw new ApiException(errors);
        }
    } catch (ApiException t) {
        throw t;
    } catch (Throwable t) {
        _logger.error("Error checking api parameters", t);
        throw new ApsSystemException("Internal Error", t);
    }
}
Also used : ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) ApiMethodParameter(org.entando.entando.aps.system.services.api.model.ApiMethodParameter) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 80 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class CacheInfoManager method aroundCacheInfoEvictMethod.

@Around("@annotation(cacheInfoEvict)")
public Object aroundCacheInfoEvictMethod(ProceedingJoinPoint pjp, CacheInfoEvict cacheInfoEvict) throws Throwable {
    try {
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        Method targetMethod = methodSignature.getMethod();
        Class targetClass = pjp.getTarget().getClass();
        Method effectiveTargetMethod = targetClass.getMethod(targetMethod.getName(), targetMethod.getParameterTypes());
        String[] cacheNames = cacheInfoEvict.value();
        Object groupsCsv = this.evaluateExpression(cacheInfoEvict.groups().toString(), targetMethod, pjp.getArgs(), effectiveTargetMethod, targetClass);
        if (null != groupsCsv && groupsCsv.toString().trim().length() > 0) {
            String[] groups = groupsCsv.toString().split(",");
            for (String group : groups) {
                for (String cacheName : cacheNames) {
                    this.flushGroup(cacheName, group);
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error while flushing group", t);
        throw new ApsSystemException("Error while flushing group", t);
    }
    return pjp.proceed();
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15