use of py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationServiceImpl method addOrganization.
@Override
public OrganizationDTO addOrganization(OrganizationDTO organizationDTO) {
organizationRepository.findOneByName(organizationDTO.getName()).ifPresent(organization -> {
throw new CustomParameterizedException("Organisation already exists", new ImmutableMultimap.Builder<String, String>().put("name", organization.getName()).build().asMap());
});
OrganizationEntity organization = new OrganizationEntity();
BeanUtils.copyProperties(organizationDTO, organization);
ApplicationEntity application = applicationRepository.findById(organizationDTO.getApplication().getId());
organization.setApplication(application);
organization.setActive(true);
if (organizationDTO.getFile() != null) {
ImageDTO imageDTO = ImageParser.parse(organizationDTO.getFile(), applicationProperties.getAws().getOrgsImageDirectory());
String generatedURL = imageUploadService.uploadImage(imageDTO);
organization.setLogoUrl(generatedURL);
}
return organizationMapper.entityToDto(organizationRepository.save(organization));
}
use of py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationServiceImpl method updateOrganization.
@Override
public OrganizationDTO updateOrganization(Long organizationId, OrganizationDTO organizationDTO) {
checkArgument(organizationId > 0, "Argument was %s but expected nonnegative", organizationId);
return Optional.ofNullable(organizationRepository.findOne(organizationId)).map(organization -> {
organization.setName(organizationDTO.getName());
organization.setDescription(organizationDTO.getDescription());
organization.setInformation(organizationDTO.getInformation());
if (organizationDTO.getFile() != null) {
ImageDTO imageDTO = ImageParser.parse(organizationDTO.getFile(), applicationProperties.getAws().getOrgsImageDirectory());
String generatedURL = imageUploadService.uploadImage(imageDTO);
if (generatedURL != null) {
imageUploadService.deleteImage(organization.getLogoUrl(), applicationProperties.getAws().getOrgsImageDirectory());
organization.setLogoUrl(generatedURL);
}
}
LOG.debug("Changed Information for Organization: {}", organization);
return organizationRepository.save(organization);
}).map(organizationMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Organization does not exist"));
}
use of py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ApplicationServiceImpl method addApplication.
@Override
public ApplicationDTO addApplication(ApplicationDTO applicationDTO) {
applicationRepository.findOneByName(applicationDTO.getName()).ifPresent(application -> {
throw new CustomParameterizedException("Application already exists", new ImmutableMultimap.Builder<String, String>().put("name", application.getName()).build().asMap());
});
ApplicationEntity application = new ApplicationEntity();
BeanUtils.copyProperties(applicationDTO, application);
application.setHub(true);
application.setActive(true);
if (applicationDTO.getFile() != null) {
ImageDTO imageDTO = ImageParser.parse(applicationDTO.getFile(), applicationProperties.getAws().getHubsImageDirectory());
String generatedURL = imageUploadService.uploadImage(imageDTO);
application.setLogoUrl(generatedURL);
}
return applicationMapper.entityToDto(applicationRepository.save(application));
}
use of py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class ApplicationServiceImpl method updateApplication.
@Override
public ApplicationDTO updateApplication(Long applicationId, ApplicationDTO applicationDTO) {
checkArgument(applicationId > 0, "Argument was %s but expected nonnegative", applicationId);
return Optional.ofNullable(applicationRepository.findOne(applicationId)).map(application -> {
application.setName(applicationDTO.getName());
application.setDescription(applicationDTO.getDescription());
application.setInformation(applicationDTO.getInformation());
if (applicationDTO.getFile() != null) {
ImageDTO imageDTO = ImageParser.parse(applicationDTO.getFile(), applicationProperties.getAws().getHubsImageDirectory());
String generatedURL = imageUploadService.uploadImage(imageDTO);
if (generatedURL != null) {
imageUploadService.deleteImage(application.getLogoUrl(), applicationProperties.getAws().getHubsImageDirectory());
application.setLogoUrl(generatedURL);
}
}
LOG.debug("Changed Information for Application: {}", application);
return applicationRepository.save(application);
}).map(applicationMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Application does not exist"));
}
use of py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilyServiceImpl method imageUpload.
@Override
public String imageUpload(Long idFamily, MultipartFile multipartFile) throws IOException {
FamilyEntity familyEntity = familyRepository.findOne(idFamily);
if (familyEntity == null) {
throw new UnknownResourceException(i18n.translate("family.notExist"));
}
String familiesImageDirectory = this.applicationProperties.getAws().getFamiliesImageDirectory();
ImageDTO image = ImageParser.parse(multipartFile, familiesImageDirectory);
// control if image already exists: if so, deletes the old image
if (familyEntity.getImageURL() != null) {
imageUploadService.deleteImage(familyEntity.getImageURL(), familiesImageDirectory);
}
// uploads the image and obtains its URL
String url = imageUploadService.uploadImage(image);
familyEntity.setImageURL(url);
LOG.debug("Updating family {} with image {}", familyEntity.getFamilyId(), familyEntity.getImageURL());
familyRepository.save(familyEntity);
return url;
}
Aggregations