Search in sources :

Example 31 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class AbstractEntityService method updateEntityType.

protected synchronized O updateEntityType(String entityManagerCode, EntityTypeDtoRequest request, BindingResult bindingResult) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    try {
        if (null == entityManager.getEntityPrototype(request.getCode())) {
            this.addError(EntityTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, bindingResult, new String[] { request.getCode() }, "entityType.notExists");
            return null;
        }
        IDtoBuilder<I, O> builder = this.getEntityTypeFullDtoBuilder(entityManager);
        I entityPrototype = this.createEntityType(entityManager, request, bindingResult);
        if (bindingResult.hasErrors()) {
            return null;
        } else {
            ((IEntityTypesConfigurer) entityManager).updateEntityPrototype(entityPrototype);
            I newPrototype = (I) entityManager.getEntityPrototype(request.getCode());
            O newType = builder.convert(newPrototype);
            newType.setStatus(String.valueOf(entityManager.getStatus(request.getCode())));
            return newType;
        }
    } catch (Throwable e) {
        logger.error("Error updating entity type", e);
        throw new RestServerError("error updating entity type", e);
    }
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 32 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class GroupService method addGroup.

@Override
public GroupDto addGroup(GroupRequest groupRequest) {
    try {
        Group group = this.createGroup(groupRequest);
        this.getGroupManager().addGroup(group);
        return this.getDtoBuilder().convert(group);
    } catch (ApsSystemException e) {
        logger.error("Error adding group", e);
        throw new RestServerError("error add group", e);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 33 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class GroupService method removeGroup.

@Override
public void removeGroup(String groupName) {
    try {
        Group group = this.getGroupManager().getGroup(groupName);
        BeanPropertyBindingResult validationResult = this.checkGroupForDelete(group);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        if (null != group) {
            this.getGroupManager().removeGroup(group);
        }
    } catch (ApsSystemException e) {
        logger.error("Error in delete group {}", groupName, e);
        throw new RestServerError("error in delete group", e);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 34 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class GroupService method getGroups.

@SuppressWarnings("rawtypes")
@Override
public PagedMetadata<GroupDto> getGroups(RestListRequest restListReq) {
    try {
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(restListReq.buildFieldSearchFilters());
        filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(GroupDto.getEntityFieldName(i.getKey())));
        SearcherDaoPaginatedResult<Group> groups = this.getGroupManager().getGroups(filters);
        List<GroupDto> dtoList = dtoBuilder.convert(groups.getList());
        PagedMetadata<GroupDto> pagedMetadata = new PagedMetadata<>(restListReq, groups);
        pagedMetadata.setBody(dtoList);
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search groups", t);
        throw new RestServerError("error in search groups", t);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Group(com.agiletec.aps.system.services.group.Group) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) Map(java.util.Map) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupValidator(org.entando.entando.web.group.validator.GroupValidator) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) BeansException(org.springframework.beans.BeansException) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Optional(java.util.Optional) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) Group(com.agiletec.aps.system.services.group.Group) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 35 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class GroupService method getReferencesInfo.

public Map<String, Boolean> getReferencesInfo(Group group) {
    Map<String, Boolean> references = new HashMap<String, Boolean>();
    try {
        String[] defNames = applicationContext.getBeanNamesForType(GroupUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = applicationContext.getBean(defNames[i]);
            } catch (Throwable t) {
                logger.error("error in hasReferencingObjects", t);
                service = null;
            }
            if (service != null) {
                GroupUtilizer<?> groupUtilizer = (GroupUtilizer<?>) service;
                List<?> utilizers = groupUtilizer.getGroupUtilizers(group.getName());
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(groupUtilizer.getName(), true);
                } else {
                    references.put(groupUtilizer.getName(), false);
                }
            }
        }
    } catch (ApsSystemException ex) {
        logger.error("error loading references for group {}", group.getName(), ex);
        throw new RestServerError("error in getReferencingObjects ", ex);
    }
    return references;
}
Also used : HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) RestServerError(org.entando.entando.aps.system.exception.RestServerError) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer)

Aggregations

RestServerError (org.entando.entando.aps.system.exception.RestServerError)65 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)45 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)28 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)25 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)13 ArrayList (java.util.ArrayList)12 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)12 IPage (com.agiletec.aps.system.services.page.IPage)10 List (java.util.List)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)9 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)8 LoggerFactory (org.slf4j.LoggerFactory)8 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 Logger (org.slf4j.Logger)7 ApsProperties (com.agiletec.aps.util.ApsProperties)6 Group (com.agiletec.aps.system.services.group.Group)5 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Category (com.agiletec.aps.system.services.category.Category)4