fix elastic configuration

This commit is contained in:
Efstratios Giannopoulos 2024-03-19 12:11:01 +02:00
parent 9a99c0c300
commit f19ac6c45e
15 changed files with 137 additions and 64 deletions

View File

@ -33,9 +33,17 @@ public class ElasticConfiguration extends AbstractElasticConfiguration {
new DmpStatusToShortConverter(),
new DescriptionStatusToShortConverter(),
new IsActiveToShortConverter(),
new DescriptionTemplateVersionStatusToShortConverter(),
new DmpVersionStatusToShortConverter(),
new DmpAccessTypeToShortConverter()
new DmpAccessTypeToShortConverter(),
new ShortToDmpStatusConverter(),
new ShortToDmpUserRoleConverter(),
new ShortToDescriptionTemplateVersionStatusConverter(),
new ShortToDmpStatusConverter(),
new ShortToDescriptionStatusConverter(),
new ShortToIsActiveConverter(),
new ShortToDmpVersionStatusConverter(),
new ShortToDmpAccessTypeConverter()
));
}
}

View File

@ -1,6 +1,5 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.DmpStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;
@ -12,3 +11,4 @@ public class DmpStatusToShortConverter implements Converter<DmpStatus, Short> {
return source.getValue();
}
}

View File

@ -1,13 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;
@WritingConverter
public class IsActiveToShortConverter implements Converter<DmpStatus, Short> {
public class IsActiveToShortConverter implements Converter<IsActive, Short> {
@Override
public Short convert(DmpStatus source) {
public Short convert(IsActive source) {
return source.getValue();
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DescriptionStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
@ReadingConverter
public class ShortToDescriptionStatusConverter implements Converter<Integer, DescriptionStatus> {
@Override
public DescriptionStatus convert(Integer source) {
return DescriptionStatus.of(source.shortValue());
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DescriptionTemplateVersionStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
@ReadingConverter
public class ShortToDescriptionTemplateVersionStatusConverter implements Converter<Integer, DescriptionTemplateVersionStatus> {
@Override
public DescriptionTemplateVersionStatus convert(Integer source) {
return DescriptionTemplateVersionStatus.of(source.shortValue());
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DmpAccessType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
@ReadingConverter
public class ShortToDmpAccessTypeConverter implements Converter<Integer, DmpAccessType> {
@Override
public DmpAccessType convert(Integer source) {
return DmpAccessType.of(source.shortValue());
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.*;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
@ReadingConverter
public class ShortToDmpStatusConverter implements Converter<Integer, DmpStatus> {
@Override
public DmpStatus convert(Integer source) {
return DmpStatus.of(source.shortValue());
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DmpUserRole;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
@ReadingConverter
public class ShortToDmpUserRoleConverter implements Converter<Integer, DmpUserRole> {
@Override
public DmpUserRole convert(Integer source) {
return DmpUserRole.of(source.shortValue());
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.DmpVersionStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
@ReadingConverter
public class ShortToDmpVersionStatusConverter implements Converter<Integer, DmpVersionStatus> {
@Override
public DmpVersionStatus convert(Integer source) {
return DmpVersionStatus.of(source.shortValue());
}
}

View File

@ -0,0 +1,14 @@
package eu.eudat.elastic.converter;
import eu.eudat.commons.enums.IsActive;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
@ReadingConverter
public class ShortToIsActiveConverter implements Converter<Integer, IsActive> {
@Override
public IsActive convert(Integer source) {
return IsActive.of(source.shortValue());
}
}

View File

@ -284,11 +284,14 @@ public class ElasticServiceImpl implements ElasticService {
public void deleteDmp(DmpEntity dmp) throws IOException {
if (!this.enabled()) return;
this.ensureIndexes();
this.elasticsearchTemplate.delete(dmp.getId(), IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
DmpElasticEntity dmpElasticEntity = this.elasticsearchTemplate.get(dmp.getId().toString(),DmpElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
if (dmpElasticEntity == null) return;
this.elasticsearchTemplate.delete(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(dmp.getId())).collectAs(new BaseFieldSet().ensure(Description._id));
for (DescriptionEntity description: descriptions) {
this.elasticsearchTemplate.delete(description.getId(), IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
if (descriptionElasticEntity == null) continue;
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
}
}
@ -312,7 +315,10 @@ public class ElasticServiceImpl implements ElasticService {
if (!this.enabled()) return;
this.ensureIndexes();
this.elasticsearchTemplate.delete(description.getId(), IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
if (descriptionElasticEntity == null) return;
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId());
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity.getIsActive().equals(IsActive.Active)) {

View File

@ -1,4 +1,4 @@
package eu.eudat.cache.transformer;
package eu.eudat.service.transformer;
import eu.eudat.configurations.deposit.DepositCacheOptions;

View File

@ -2,7 +2,6 @@ package eu.eudat.service.transformer;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.cache.transformer.FileTransformerConfigurationCache;
import eu.eudat.commonmodels.models.FileEnvelopeModel;
import eu.eudat.commonmodels.models.description.DescriptionModel;
import eu.eudat.commonmodels.models.dmp.DmpModel;

View File

@ -1,52 +0,0 @@
//package eu.eudat.utilities.pdf;
//
//import eu.eudat.model.file.FileEnvelope;
//import org.apache.commons.io.IOUtils;
//import org.springframework.core.env.Environment;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.MediaType;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.web.client.RestTemplate;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.nio.file.Files;
//import java.util.UUID;
//
//public class PDFUtils {
//
// public static File convertToPDF(eu.eudat.depositinterface.models.FileEnvelope file, Environment environment) throws IOException {
// FileEnvelope envelope = new FileEnvelope();
// envelope.setFilename(file.getFilename());
//// envelope.setFile(file.getFile());
// return convertToPDF(envelope, environment);
// }
//
// public static File convertToPDF(FileEnvelope file, Environment environment) throws IOException {
// LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
// String uuid = UUID.randomUUID().toString();
// map.add("files", new FileSystemResource(file.getFile()));
// map.add("filename", uuid + ".pdf");
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
// headers.add("Content-disposition", "attachment; filename=" + uuid + ".pdf");
// headers.add("Content-type", "application/pdf");
//
// HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
// map, headers);
//
// byte[] queueResult = new RestTemplate().postForObject(environment.getProperty("pdf.converter.url") + "forms/libreoffice/convert"
// , requestEntity, byte[].class);
//
// File resultPdf = new File(environment.getProperty("temp.temp") + uuid + ".pdf");
// FileOutputStream output = new FileOutputStream(resultPdf);
// IOUtils.write(queueResult, output);
// output.close();
// Files.deleteIfExists(file.getFile().toPath());
//
// return resultPdf;
// }
//}

View File

@ -56,7 +56,7 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.7.0</version>
<version>8.5.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
@ -412,6 +412,19 @@
</property>
</activation>
</profile>
<profile>
<id>cite-dev</id>
<repositories>
<repository>
<id>cite-maven</id>
<name>CITE Maven Repository</name>
<url>https://crepo.cite.gr/repository/cite-maven/</url>
</repository>
</repositories>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
</project>