fixed tests and cleanup on dossier status removal
This commit is contained in:
parent
03bcfb8cc3
commit
f1181177d4
@ -18,6 +18,8 @@ public interface DossierStatusResource {
|
||||
String DOSSIER_STATUS_ID = "dossierStatusId";
|
||||
String DOSSIER_STATUS_ID_PATH_VARIABLE = "/{" + DOSSIER_STATUS_ID + "}";
|
||||
|
||||
String DOSSIER_STATUS_REPLACE_ID = "replaceDossierStatusId";
|
||||
|
||||
@ResponseBody
|
||||
@ResponseStatus(HttpStatus.ACCEPTED)
|
||||
@PostMapping(value = DOSSIER_STATUS_PATH, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ -41,6 +43,7 @@ public interface DossierStatusResource {
|
||||
@ResponseBody
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
@DeleteMapping(value = DOSSIER_STATUS_PATH + DOSSIER_STATUS_ID_PATH_VARIABLE)
|
||||
void deleteDossierStatus(@PathVariable(DOSSIER_STATUS_ID) String dossierStatusId);
|
||||
void deleteDossierStatus(@PathVariable(DOSSIER_STATUS_ID) String dossierStatusId,
|
||||
@RequestParam(value = DOSSIER_STATUS_REPLACE_ID, required = false) String replaceDossierStatusId);
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierStatusEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DossierStatusRepository;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.CreateOrUpdateDossierStatusRequest;
|
||||
@ -57,7 +58,25 @@ public class DossierStatusPersistenceService {
|
||||
return dossierStatusRepository.findById(dossierStatusId).orElseThrow(() -> new NotFoundException(String.format(DOSSIER_STATUS_NOT_FOUND_MESSAGE, dossierStatusId)));
|
||||
}
|
||||
|
||||
public void deleteDossierStatus(String dossierStatusId) {
|
||||
@Transactional
|
||||
public void deleteDossierStatus(String dossierStatusId, String replaceDossierStatusId) {
|
||||
|
||||
|
||||
dossierStatusRepository.findById(dossierStatusId).ifPresent(toDeleteDossierStatus -> {
|
||||
|
||||
DossierStatusEntity replaceDossierStatusEntity = null;
|
||||
if (replaceDossierStatusId != null) {
|
||||
replaceDossierStatusEntity = dossierStatusRepository.findById(replaceDossierStatusId).orElseThrow(() -> new NotFoundException("Dossier Status not found: " + replaceDossierStatusId));
|
||||
}
|
||||
|
||||
if (replaceDossierStatusEntity != null && !replaceDossierStatusEntity.getDossierTemplateId().equals(toDeleteDossierStatus.getDossierTemplateId())) {
|
||||
throw new BadRequestException("Cannot replace with dossier status from different template");
|
||||
}
|
||||
|
||||
for (var dossier : toDeleteDossierStatus.getDossiers()) {
|
||||
dossier.setDossierStatus(replaceDossierStatusEntity);
|
||||
}
|
||||
});
|
||||
dossierStatusRepository.deleteById(dossierStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.do
|
||||
import com.iqser.red.service.persistence.service.v1.api.resources.DossierStatusResource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
@ -32,18 +34,18 @@ public class DossierStatusController implements DossierStatusResource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DossierStatusInfo> getAllDossierStatusForTemplate(String dossierTemplateId) {
|
||||
public List<DossierStatusInfo> getAllDossierStatusForTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId) {
|
||||
return convert(dossierStatusPersistenceService.getAllDossierStatus(), DossierStatusInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DossierStatusInfo getDossierStatus(String dossierStatusId) {
|
||||
public DossierStatusInfo getDossierStatus(@PathVariable(DOSSIER_STATUS_ID) String dossierStatusId) {
|
||||
|
||||
return convert(dossierStatusPersistenceService.getDossierStatus(dossierStatusId), DossierStatusInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDossierStatus(String dossierStatusId) {
|
||||
dossierStatusPersistenceService.deleteDossierStatus(dossierStatusId);
|
||||
public void deleteDossierStatus(String dossierStatusId, @RequestParam(value = DOSSIER_STATUS_REPLACE_ID, required = false) String replaceDossierStatusId) {
|
||||
dossierStatusPersistenceService.deleteDossierStatus(dossierStatusId,replaceDossierStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,11 +69,11 @@ public class DossierTesterAndProvider {
|
||||
return provideTestDossier(testTemplate, "Dossier1");
|
||||
}
|
||||
|
||||
public Dossier provideTestDossier(String filename) {
|
||||
public Dossier provideTestDossier(String dossierName) {
|
||||
|
||||
var testTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
|
||||
|
||||
return provideTestDossier(testTemplate, filename);
|
||||
return provideTestDossier(testTemplate, dossierName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ public class DossierStatusTest extends AbstractPersistenceServerServiceTest {
|
||||
// update
|
||||
CreateOrUpdateDossierRequest cru = new CreateOrUpdateDossierRequest();
|
||||
BeanUtils.copyProperties(testDossier, cru);
|
||||
cru.setDossierTemplateId(testDossier.getId());
|
||||
cru.setDossierTemplateId(testDossier.getDossierTemplateId());
|
||||
cru.setDossierStatusId(null);
|
||||
|
||||
var updated = dossierClient.updateDossier(cru, testDossier.getId());
|
||||
|
||||
@ -168,8 +168,8 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
ruleSetRepository.deleteAll();
|
||||
smtpRepository.deleteAll();
|
||||
fileRepository.deleteAll();
|
||||
dossierStatusRepository.deleteAll();
|
||||
dossierRepository.deleteAll();
|
||||
dossierStatusRepository.deleteAll();
|
||||
dossierTemplateRepository.deleteAll();
|
||||
notificationPreferencesRepository.deleteAll();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user