Search in sources :

Example 6 with FieldSearchFilter

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

the class DataObjectModelService method getDataObjectModels.

@Override
public PagedMetadata<DataModelDto> getDataObjectModels(RestListRequest restListReq) {
    PagedMetadata<DataModelDto> pagedMetadata = null;
    try {
        List<FieldSearchFilter> filters = new ArrayList<>(restListReq.buildFieldSearchFilters());
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        filters.stream().filter(searchFilter -> searchFilter.getKey() != null).forEach(searchFilter -> {
            searchFilter.setKey(DataModelDto.getEntityFieldName(searchFilter.getKey()));
            if (searchFilter.getKey().equals("modelid") && null != searchFilter.getValue()) {
                String stringValue = searchFilter.getValue().toString();
                Long value = Long.parseLong(stringValue);
                searchFilter = new FieldSearchFilter("modelid", value, true);
            }
        });
        SearcherDaoPaginatedResult<DataObjectModel> models = this.getDataObjectModelManager().getDataObjectModels(filters);
        List<DataModelDto> dtoList = this.getDtoBuilder().convert(models.getList());
        pagedMetadata = new PagedMetadata<>(restListReq, models);
        pagedMetadata.setBody(dtoList);
    } catch (Throwable t) {
        logger.error("error in search data models", t);
        throw new RestServerError("error in search data models", t);
    }
    return pagedMetadata;
}
Also used : Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) GuiFragmentValidator(org.entando.entando.web.guifragment.validator.GuiFragmentValidator) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) Map(java.util.Map) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) DataObjectModelRequest(org.entando.entando.web.dataobjectmodel.model.DataObjectModelRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ArrayList(java.util.ArrayList) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 7 with FieldSearchFilter

use of com.agiletec.aps.system.common.FieldSearchFilter 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 8 with FieldSearchFilter

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

the class GuiFragmentManager method getGuiFragments.

@Override
public SearcherDaoPaginatedResult<GuiFragment> getGuiFragments(List<FieldSearchFilter> filters) throws ApsSystemException {
    SearcherDaoPaginatedResult<GuiFragment> pagedResult = null;
    try {
        List<GuiFragment> fragments = new ArrayList<>();
        FieldSearchFilter[] filtersArray = filters.toArray(new FieldSearchFilter[filters.size()]);
        int count = this.getGuiFragmentDAO().countGuiFragments(filtersArray);
        List<String> codes = this.searchGuiFragments(filtersArray);
        for (String code : codes) {
            fragments.add(this.getGuiFragment(code));
        }
        pagedResult = new SearcherDaoPaginatedResult<>(count, fragments);
    } catch (Throwable t) {
        logger.error("Error searching GuiFragments", t);
        throw new ApsSystemException("Error searching GuiFragments", t);
    }
    return pagedResult;
}
Also used : ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 9 with FieldSearchFilter

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

the class ActionLogDAO method getActivityStream.

@Override
public List<Integer> getActivityStream(List<String> userGroupCodes) {
    Connection conn = null;
    List<Integer> idList = new ArrayList<Integer>();
    PreparedStatement stat = null;
    ResultSet result = null;
    try {
        conn = this.getConnection();
        FieldSearchFilter filter1 = new FieldSearchFilter("actiondate");
        filter1.setOrder(FieldSearchFilter.DESC_ORDER);
        FieldSearchFilter filter2 = new FieldSearchFilter("activitystreaminfo");
        FieldSearchFilter[] filters = { filter1, filter2 };
        List<String> groupCodes = (null != userGroupCodes && userGroupCodes.contains(Group.ADMINS_GROUP_NAME)) ? null : userGroupCodes;
        stat = this.buildStatement(filters, groupCodes, conn);
        result = stat.executeQuery();
        while (result.next()) {
            idList.add(result.getInt(1));
        }
    } catch (Throwable t) {
        _logger.error("Error loading activity stream records", t);
        throw new RuntimeException("Error loading activity stream records", t);
    } finally {
        closeDaoResources(result, stat, conn);
    }
    return idList;
}
Also used : Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 10 with FieldSearchFilter

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

the class ActionLogManager method addActionRecordByThread.

protected synchronized void addActionRecordByThread(ActionLogRecord actionRecord) throws ApsSystemException {
    try {
        Integer key = null;
        List<Integer> ids = null;
        do {
            key = this.getKeyGeneratorManager().getUniqueKeyCurrentValue();
            FieldSearchFilter filter = new FieldSearchFilter("id", key, true);
            FieldSearchFilter[] filters = { filter };
            ids = this.getActionLogDAO().getActionRecords(filters);
        } while (!ids.isEmpty());
        actionRecord.setId(key);
        actionRecord.setActionDate(new Date());
        this.getActionLogDAO().addActionRecord(actionRecord);
    } catch (Throwable t) {
        _logger.error("Error adding an actionlogger record", t);
        throw new ApsSystemException("Error adding an actionlogger record", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Date(java.util.Date)

Aggregations

FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)32 ArrayList (java.util.ArrayList)15 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 RestListRequest (org.entando.entando.web.common.model.RestListRequest)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)5 List (java.util.List)5 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 Map (java.util.Map)3 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)3 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)3 Filter (org.entando.entando.web.common.model.Filter)3 Test (org.junit.Test)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)2