Search in sources :

Example 6 with StringApiResponse

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

the class ApiEntityTypeInterface method updateEntityType.

public StringApiResponse updateEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbEntityType.getTypeCode();
        IApsEntity masterUserProfileType = this.getEntityManager().getEntityPrototype(typeCode);
        if (null == masterUserProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
        }
        Map<String, AttributeInterface> attributes = this.getEntityManager().getEntityAttributePrototypes();
        IApsEntity entityTypeToUpdate = jaxbEntityType.buildEntityType(this.getEntityManager().getEntityClass(), attributes);
        this.checkEntityTypeToUpdate(jaxbEntityType, entityTypeToUpdate, response);
        ((IEntityTypesConfigurer) this.getEntityManager()).updateEntityPrototype(entityTypeToUpdate);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "updateEntityType");
        throw new ApsSystemException("Error updating entity 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 7 with StringApiResponse

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

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

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

use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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)

Aggregations

StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)28 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)23 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)20 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)8 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)6 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)5 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)4 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)4 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)2 BaseResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean)2 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)2 Properties (java.util.Properties)2 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1