Search in sources :

Example 1 with FamilyFilterDTO

use of py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotServiceImpl method countSnapshotTaken.

@Override
public SnapshotTaken countSnapshotTaken(FamilyFilterDTO filter) {
    List<SnapshotEconomicEntity> snapshots = getSnapshotsLess2MonthsByFamilies(filter);
    Map<String, Long> result = snapshots.stream().collect(Collectors.groupingBy(item -> item.getCreatedAt().toLocalDate().with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ISO_DATE), Collectors.counting()));
    SnapshotTaken t = new SnapshotTaken();
    t.setByMonth(result);
    return t;
}
Also used : SnapshotEconomicMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotEconomicMapper) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) LoggerFactory(org.slf4j.LoggerFactory) FamilyService(py.org.fundacionparaguaya.pspserver.families.services.FamilyService) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) I18n(py.org.fundacionparaguaya.pspserver.config.I18n) StringUtils(org.apache.commons.lang3.StringUtils) UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO) SnapshotEconomicSpecification.byApplication(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.byApplication) SnapshotIndicatorPriority(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicatorPriority) PersonMapper(py.org.fundacionparaguaya.pspserver.families.mapper.PersonMapper) Map(java.util.Map) PersonEntity(py.org.fundacionparaguaya.pspserver.families.entities.PersonEntity) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) SnapshotService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotService) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SnapshotEconomicSpecification.createdAtLess2Months(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification.createdAtLess2Months) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) SnapshotEconomicRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SnapshotEconomicRepository) List(java.util.List) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) TopOfIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.TopOfIndicators) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO) OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) HashMap(java.util.HashMap) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ArrayList(java.util.ArrayList) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) SnapshotEconomicSpecification(py.org.fundacionparaguaya.pspserver.surveys.specifications.SnapshotEconomicSpecification) Service(org.springframework.stereotype.Service) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorPriorityService(py.org.fundacionparaguaya.pspserver.surveys.services.SnapshotIndicatorPriorityService) Logger(org.slf4j.Logger) Snapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.Snapshot) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) PropertyTitle(py.org.fundacionparaguaya.pspserver.surveys.dtos.PropertyTitle) SurveyStoplightEnum(py.org.fundacionparaguaya.pspserver.surveys.enums.SurveyStoplightEnum) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken) DateTimeFormatter(java.time.format.DateTimeFormatter) SnapshotIndicatorMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SnapshotIndicatorMapper) Transactional(org.springframework.transaction.annotation.Transactional) SnapshotEconomicEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotEconomicEntity) SnapshotTaken(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotTaken)

Example 2 with FamilyFilterDTO

use of py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class FamilyController method getAllFamilies.

@GetMapping()
public ResponseEntity<List<FamilyDTO>> getAllFamilies(@RequestParam(value = "organization_id", required = false) Long organizationId, @RequestParam(value = "country_id", required = false) Long countryId, @RequestParam(value = "city_id", required = false) Long cityId, @RequestParam(value = "free_text", required = false) String name, @RequestParam(value = "application_id", required = false) Long applicationId, @RequestParam(value = "last_modified_gt", required = false) String lastModifiedGt, @AuthenticationPrincipal UserDetailsDTO user) {
    FamilyFilterDTO filter = FamilyFilterDTO.builder().applicationId(applicationId).organizationId(organizationId).countryId(countryId).cityId(cityId).name(name).isActive(true).lastModifiedGt(lastModifiedGt).build();
    List<FamilyDTO> families = familyService.listFamilies(filter, user);
    return ResponseEntity.ok(families);
}
Also used : FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) FamilyDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with FamilyFilterDTO

use of py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class ApplicationServiceImpl method getApplicationDashboard.

@Override
public ApplicationDTO getApplicationDashboard(Long applicationId, UserDetailsDTO details) {
    ApplicationDTO dto = getUserApplication(details, applicationId);
    Long organizationId = Optional.ofNullable(details.getOrganization()).orElse(new OrganizationDTO()).getId();
    FamilyFilterDTO filter = FamilyFilterDTO.builder().applicationId(dto.getId()).organizationId(organizationId).build();
    DashboardDTO dashboard = DashboardDTO.of(familyService.countFamiliesByFilter(filter), null, null, null, snapshotService.countSnapshotTaken(filter));
    dto.setDashboard(dashboard);
    return dto;
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) DashboardDTO(py.org.fundacionparaguaya.pspserver.network.dtos.DashboardDTO)

Example 4 with FamilyFilterDTO

use of py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class FamilyServiceImpl method listFamilies.

@Override
public List<FamilyDTO> listFamilies(FamilyFilterDTO filter, UserDetailsDTO userDetails) {
    FamilyFilterDTO newFilter = buildFilterFromFilterAndUser(filter, userDetails);
    List<FamilyEntity> entityList = familyRepository.findAll(where(byFilter(newFilter)));
    return familyMapper.entityListToDtoList(entityList);
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO)

Example 5 with FamilyFilterDTO

use of py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class OrganizationServiceImpl method getOrganizationDashboard.

@Override
public OrganizationDTO getOrganizationDashboard(Long organizationId, UserDetailsDTO details) {
    OrganizationDTO dto = new OrganizationDTO();
    if (details.getOrganization() != null && details.getOrganization().getId() != null) {
        dto = getOrganizationById(details.getOrganization().getId());
    } else if (organizationId != null) {
        dto = getOrganizationById(organizationId);
    }
    Long applicationId = Optional.ofNullable(details.getApplication()).orElse(new ApplicationDTO()).getId();
    FamilyFilterDTO filter = FamilyFilterDTO.builder().applicationId(applicationId).organizationId(dto.getId()).build();
    DashboardDTO dashboard = DashboardDTO.of(familyService.countFamiliesByFilter(filter), null, snapshotServiceImpl.getTopOfIndicators(organizationId), countSnapshotIndicators(organizationId), null);
    dto.setDashboard(dashboard);
    return dto;
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) FamilyFilterDTO(py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) DashboardDTO(py.org.fundacionparaguaya.pspserver.network.dtos.DashboardDTO)

Aggregations

FamilyFilterDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyFilterDTO)5 FamilyDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO)2 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)2 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)2 DashboardDTO (py.org.fundacionparaguaya.pspserver.network.dtos.DashboardDTO)2 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 TemporalAdjusters (java.time.temporal.TemporalAdjusters)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)1 Service (org.springframework.stereotype.Service)1