Search in sources :

Example 26 with StringApiResponse

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

the class TestApiContentInterface method testCreateNewContent.

protected void testCreateNewContent(MediaType mediaType, String contentId) throws Throwable {
    String dateNow = DateConverter.getFormattedDate(new Date(), JacmsSystemConstants.CONTENT_METADATA_DATE_FORMAT);
    EntitySearchFilter filter = new EntitySearchFilter(IContentManager.CONTENT_CREATION_DATE_FILTER_KEY, false, dateNow, null);
    EntitySearchFilter[] filters = { filter };
    List<String> ids = this._contentManager.searchId(filters);
    assertTrue(ids.isEmpty());
    JAXBContent jaxbContent = this.testGetContent(mediaType, "admin", contentId, "it");
    ApiResource contentResource = this.getApiCatalogManager().getResource("jacms", "content");
    ApiMethod postMethod = contentResource.getPostMethod();
    Properties properties = super.createApiProperties("admin", "it", mediaType);
    try {
        jaxbContent.setId(null);
        Object response = this.getResponseBuilder().createResponse(postMethod, jaxbContent, properties);
        assertNotNull(response);
        assertTrue(response instanceof StringApiResponse);
        assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
        ids = this._contentManager.searchId(filters);
        assertEquals(1, ids.size());
        String newContentId = ids.get(0);
        Content newContent = this._contentManager.loadContent(newContentId, false);
        Content masterContent = this._contentManager.loadContent(contentId, true);
        List<AttributeInterface> attributes = masterContent.getAttributeList();
        for (int i = 0; i < attributes.size(); i++) {
            AttributeInterface attribute = attributes.get(i);
            AttributeInterface newAttribute = (AttributeInterface) newContent.getAttribute(attribute.getName());
            this.checkAttributes(attribute, newAttribute);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        ids = this._contentManager.searchId(filters);
        if (!ids.isEmpty()) {
            for (int i = 0; i < ids.size(); i++) {
                String id = ids.get(i);
                Content content = this._contentManager.loadContent(id, false);
                this._contentManager.deleteContent(content);
            }
        }
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) Date(java.util.Date) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 27 with StringApiResponse

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

Example 28 with StringApiResponse

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

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