Adding export on dmp service and controller (existing service not yet wired up)
This commit is contained in:
parent
d50a058296
commit
34ce4f6928
|
@ -13,6 +13,7 @@ import gr.cite.tools.exception.MyNotFoundException;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import jakarta.xml.bind.JAXBException;
|
import jakarta.xml.bind.JAXBException;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
@ -22,6 +23,10 @@ import java.util.UUID;
|
||||||
|
|
||||||
public interface DmpService {
|
public interface DmpService {
|
||||||
|
|
||||||
|
enum DmpExportType {
|
||||||
|
Word, Json, Xml;
|
||||||
|
}
|
||||||
|
|
||||||
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
|
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
|
||||||
|
|
||||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||||
|
@ -32,4 +37,6 @@ public interface DmpService {
|
||||||
|
|
||||||
List<DmpUserEntity> assignUsers(UUID dmp, List<DmpUserPersist> model, FieldSet fields) throws InvalidApplicationException;
|
List<DmpUserEntity> assignUsers(UUID dmp, List<DmpUserPersist> model, FieldSet fields) throws InvalidApplicationException;
|
||||||
|
|
||||||
|
ResponseEntity<byte[]> export(UUID id, DmpExportType exportType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,16 +48,17 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.management.InvalidApplicationException;
|
import javax.management.InvalidApplicationException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -349,6 +350,26 @@ public class DmpServiceImpl implements DmpService {
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<byte[]> export(UUID id, DmpExportType exportType) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
switch (exportType){
|
||||||
|
case Xml -> {
|
||||||
|
headers.setContentType(MediaType.APPLICATION_XML);
|
||||||
|
return new ResponseEntity<>(new byte[]{}, headers, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
case Json -> {
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
return new ResponseEntity<>(new byte[]{}, headers, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
case Word -> {
|
||||||
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
return new ResponseEntity<>(new byte[]{}, headers, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ResponseEntity.badRequest().body(new byte[]{});
|
||||||
|
}
|
||||||
|
|
||||||
private DmpEntity patchAndSave(DmpPersist model) throws JsonProcessingException, InvalidApplicationException {
|
private DmpEntity patchAndSave(DmpPersist model) throws JsonProcessingException, InvalidApplicationException {
|
||||||
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import jakarta.xml.bind.JAXBException;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -183,4 +184,11 @@ public class DmpController {
|
||||||
return new QueryResult<>(models);
|
return new QueryResult<>(models);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("{id}/export/{type}")
|
||||||
|
public ResponseEntity<byte[]> export(@PathVariable("id") UUID id, @PathVariable("type") String exportType){
|
||||||
|
logger.debug(new MapLogEntry("exporting dmp"));
|
||||||
|
|
||||||
|
return this.dmpService.export(id, DmpService.DmpExportType.valueOf(exportType));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue