Search in sources :

Example 21 with ApiException

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

the class ApiUserProfileInterface method addUserProfile.

public StringApiResponse addUserProfile(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 + "' already 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().addProfile(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 adding user profile", t);
        // ApsSystemUtils.logThrowable(t, this, "addUserProfile");
        throw new ApsSystemException("Error adding 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 22 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException 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 23 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException 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 24 with ApiException

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

the class ApiRestStatusServer method getApiStatus.

@GET
@Produces({ "application/json", "application/xml", "application/javascript" })
@Path("/{namespace}/{resourceName}/{httpMethod}")
public Object getApiStatus(@PathParam("httpMethod") String httpMethodString, @PathParam("namespace") String namespace, @PathParam("resourceName") String resourceName, @Context HttpServletRequest request) {
    StringApiResponse response = new StringApiResponse();
    ApiMethod.HttpMethod httpMethod = Enum.valueOf(ApiMethod.HttpMethod.class, httpMethodString.toUpperCase());
    try {
        IResponseBuilder responseBuilder = (IResponseBuilder) ApsWebApplicationUtils.getBean(SystemConstants.API_RESPONSE_BUILDER, request);
        ApiMethod apiMethod = responseBuilder.extractApiMethod(httpMethod, namespace, resourceName);
        if (null != apiMethod.getRequiredPermission()) {
            response.setResult(ApiStatus.AUTHORIZATION_REQUIRED.toString(), null);
        } else if (apiMethod.getRequiredAuth()) {
            response.setResult(ApiStatus.AUTHENTICATION_REQUIRED.toString(), null);
        } else {
            response.setResult(ApiStatus.FREE.toString(), null);
        }
    } catch (ApiException ae) {
        response.addErrors(((ApiException) ae).getErrors());
        response.setResult(ApiStatus.INACTIVE.toString(), null);
    } catch (Throwable t) {
        return this.buildErrorResponse(httpMethod, namespace, resourceName, t);
    }
    return response;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with ApiException

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

the class ResponseBuilder method buildApiResponseObject.

private AbstractApiResponse buildApiResponseObject(ApiMethod apiMethod) throws ApiException {
    AbstractApiResponse apiResponse = null;
    try {
        Class responseClass = Class.forName(apiMethod.getResponseClassName());
        apiResponse = (AbstractApiResponse) responseClass.newInstance();
    } catch (Exception e) {
        _logger.error("Error creating instance of response '{}'", apiMethod.getResponseClassName(), e);
    }
    return apiResponse;
}
Also used : AbstractApiResponse(org.entando.entando.aps.system.services.api.model.AbstractApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeansException(org.springframework.beans.BeansException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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