Search in sources :

Example 41 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity 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 42 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity 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 43 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity 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 44 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.

the class EntityTypesInfoTag method getMasterObject.

@Override
protected Object getMasterObject(String keyValue) throws Throwable {
    String managerNameValue = (String) super.findValue(keyValue, String.class);
    try {
        IEntityManager entityManager = (IEntityManager) ApsWebApplicationUtils.getBean(managerNameValue, this.pageContext);
        if (null != entityManager) {
            List<IApsEntity> entityTypes = new ArrayList<IApsEntity>();
            Map<String, IApsEntity> typeMap = entityManager.getEntityPrototypes();
            if (null != typeMap) {
                BeanComparator c = new BeanComparator(this.getOrderBy());
                entityTypes.addAll(typeMap.values());
                Collections.sort(entityTypes, c);
            }
            return entityTypes;
        } else {
            _logger.debug("Null entity manager : service name '{}'", managerNameValue);
        }
    } catch (Throwable t) {
        String message = "Error extracting entity types : entity manager '" + managerNameValue + "'";
        _logger.error("Error extracting entity types : entity manager '{}'", managerNameValue, t);
        // ApsSystemUtils.logThrowable(t, this, "getMasterObject", message);
        throw new ApsSystemException(message, t);
    }
    return null;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 45 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.

the class TestEntityManagersAction method testEditAttribute.

public void testEditAttribute() throws Throwable {
    // Search an entity manager
    String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
    if (null == defNames || defNames.length == 0)
        return;
    String entityManagerName = defNames[0];
    IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
    // get the entites managed by the ApsEntityManager
    Map<String, IApsEntity> entities = entityManager.getEntityPrototypes();
    if (null == entities || entities.size() == 0)
        return;
    List<String> enitiesTypeCodes = new ArrayList<String>();
    enitiesTypeCodes.addAll(entities.keySet());
    // get the first entity type code available
    String entityTypeCode = enitiesTypeCodes.get(0);
    List<AttributeInterface> attributes = entities.get(entityTypeCode).getAttributeList();
    // get the first attribute
    for (int i = 0; i < attributes.size(); i++) {
        AttributeInterface currentAttribute = attributes.get(i);
        String attributeName = currentAttribute.getName();
        String result = this.executeEditAttribute("admin", attributeName, entityTypeCode, entityManagerName);
        assertEquals(Action.SUCCESS, result);
        EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
        assertEquals(currentAttribute.getType(), action.getAttributeTypeCode());
        assertEquals(currentAttribute.isRequired(), action.getRequired().booleanValue());
        assertEquals(currentAttribute.isSearchable(), action.getSearchable().booleanValue());
        assertEquals(currentAttribute.getIndexingType().equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT), action.getIndexable().booleanValue());
        if (currentAttribute.isTextAttribute()) {
            ITextAttribute attr = (ITextAttribute) currentAttribute;
            if (attr.getMaxLength() == -1) {
                assertNull(action.getMaxLength());
            } else {
                assertEquals(attr.getMaxLength(), action.getMaxLength().intValue());
            }
            if (attr.getMinLength() == -1) {
                assertNull(action.getMinLength());
            } else {
                assertEquals(attr.getMinLength(), action.getMinLength().intValue());
            }
            assertEquals(attr.getRegexp(), action.getRegexp());
        }
        assertEquals(ApsAdminSystemConstants.EDIT, action.getStrutsAction());
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeConfigAction(com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)

Aggregations

IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)70 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)24 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)12 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)11 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)11 ArrayList (java.util.ArrayList)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 List (java.util.List)4 BeanComparator (org.apache.commons.beanutils.BeanComparator)4 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)3 ListAttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 Widget (com.agiletec.aps.system.services.page.Widget)2 ApsProperties (com.agiletec.aps.util.ApsProperties)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)2