Search in sources :

Example 16 with IEntityManager

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

the class AbstractEntityService method getShortEntityTypes.

protected PagedMetadata<EntityTypeShortDto> getShortEntityTypes(String entityManagerCode, RestListRequest requestList) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    List<IApsEntity> entityTypes = new ArrayList<>(entityManager.getEntityPrototypes().values());
    Map<String, String> fieldMapping = this.getEntityTypeFieldNameMapping();
    entityTypes.stream().filter(i -> this.filterObjects(i, requestList.getFilter(), fieldMapping));
    Collections.sort(entityTypes, new BeanComparator(this.getFieldName(requestList.getSort(), fieldMapping)));
    if (!RestListRequest.DIRECTION_VALUE_DEFAULT.equals(requestList.getDirection())) {
        Collections.reverse(entityTypes);
    }
    List<IApsEntity> sublist = requestList.getSublist(entityTypes);
    SearcherDaoPaginatedResult<IApsEntity> result = new SearcherDaoPaginatedResult(entityTypes.size(), sublist);
    PagedMetadata<EntityTypeShortDto> pagedMetadata = new PagedMetadata<>(requestList, result);
    List<EntityTypeShortDto> body = this.getEntityTypeShortDtoBuilder().convert(sublist);
    for (EntityTypeShortDto entityTypeShortDto : body) {
        String code = entityTypeShortDto.getCode();
        entityTypeShortDto.setStatus(String.valueOf(entityManager.getStatus(code)));
    }
    pagedMetadata.setBody(body);
    return pagedMetadata;
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) EntityTypeShortDto(org.entando.entando.aps.system.services.entity.model.EntityTypeShortDto) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) BeanComparator(org.apache.commons.beanutils.BeanComparator) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 17 with IEntityManager

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

the class AbstractEntityService method deleteEntityType.

protected void deleteEntityType(String entityManagerCode, String entityTypeCode) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    try {
        IApsEntity entityType = entityManager.getEntityPrototype(entityTypeCode);
        if (null == entityType) {
            return;
        }
        List<String> ids = entityManager.searchId(entityTypeCode, null);
        if (null != ids && ids.size() > 0) {
            BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(entityType, "entityType");
            bindingResult.reject(EntityTypeValidator.ERRCODE_ENTITY_TYPE_REFERENCES, new Object[] { entityTypeCode }, "entityType.cannot.delete.references");
            throw new ValidationConflictException(bindingResult);
        }
        ((IEntityTypesConfigurer) entityManager).removeEntityPrototype(entityTypeCode);
    } catch (ApsSystemException e) {
        logger.error("Error in delete entityType {}", entityTypeCode, e);
        throw new RestServerError("error in delete entityType", e);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 18 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager 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 19 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager 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)

Example 20 with IEntityManager

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

the class TestEntityManagersAction method testInitEditEntityType.

public void testInitEditEntityType() throws Throwable {
    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);
    Map<String, IApsEntity> entityPrototypes = entityManager.getEntityPrototypes();
    if (null == entityPrototypes || entityPrototypes.size() == 0)
        return;
    IApsEntity realEntityPrototype = new ArrayList<IApsEntity>(entityPrototypes.values()).get(0);
    String result = this.executeInitEditEntityType("supervisorCoach", entityManagerName, realEntityPrototype.getTypeCode());
    assertEquals("userNotAllowed", result);
    result = this.executeInitEditEntityType("admin", null, realEntityPrototype.getTypeCode());
    assertEquals(Action.INPUT, result);
    assertEquals(1, this.getAction().getFieldErrors().size());
    assertEquals(1, this.getAction().getFieldErrors().get("entityManagerName").size());
    if (null == entityPrototypes.get("XXX")) {
        result = this.executeInitEditEntityType("admin", entityManagerName, "XXX");
        assertEquals("wrongEntityType", result);
        assertEquals(1, this.getAction().getFieldErrors().size());
        assertEquals(1, this.getAction().getFieldErrors().get("entityTypeCode").size());
    }
    result = this.executeInitEditEntityType("admin", entityManagerName, null);
    assertEquals("wrongEntityType", result);
    assertEquals(1, this.getAction().getFieldErrors().size());
    assertEquals(1, this.getAction().getFieldErrors().get("entityTypeCode").size());
    result = this.executeInitEditEntityType("admin", entityManagerName, realEntityPrototype.getTypeCode());
    assertEquals(Action.SUCCESS, result);
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Aggregations

IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)25 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)12 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 ArrayList (java.util.ArrayList)7 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)5 BeanComparator (org.apache.commons.beanutils.BeanComparator)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)1 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 List (java.util.List)1 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)1 StringListApiResponse (org.entando.entando.aps.system.services.api.model.StringListApiResponse)1