use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse in project webcert by sklintyg.
the class CopyUtkastServiceImpl method createReplacementCopy.
@Override
@Transactional("jpaTransactionManager")
public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) {
String originalIntygId = replacementRequest.getOriginalIntygId();
WebCertUser user = userService.getUser();
LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId);
try {
if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) {
LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked");
}
verifyNotReplaced(replacementRequest.getOriginalIntygId(), "create replacement");
verifyNotComplementedWithSigned(replacementRequest.getOriginalIntygId(), "create replacement");
CopyUtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId);
if (replacementRequest.isDjupintegrerad()) {
checkIntegreradEnhet(builderResponse);
}
Utkast savedUtkast = saveAndNotify(builderResponse, user);
monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId);
return new CreateReplacementCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
} catch (ModuleException | ModuleNotFoundException me) {
LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
}
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse in project webcert by sklintyg.
the class CopyUtkastServiceImplTest method testCreateReplacementCopy.
@Test
public void testCreateReplacementCopy() throws Exception {
final String reference = "ref";
WebCertUser user = new WebCertUser();
user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
when(userService.getUser()).thenReturn(user);
when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
when(createReplacementUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), eq(true), any(boolean.class), eq(true))).thenReturn(resp);
CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
assertNotNull(copyResp);
assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
verify(mockPUService).getPerson(PATIENT_SSN);
verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
verify(mockUtkastRepository).save(any(Utkast.class));
verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
verify(logService).logCreateIntyg(any(LogRequest.class));
verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse in project webcert by sklintyg.
the class CopyUtkastServiceImplTest method testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg.
@Test(expected = WebCertServiceException.class)
public void testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg() throws Exception {
final String reference = "ref";
WebCertUser user = new WebCertUser();
user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
when(userService.getUser()).thenReturn(user);
CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.values()))).thenReturn(Optional.of(ersattRelation));
CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
assertNotNull(copyResp);
assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
verify(mockPUService).getPerson(PATIENT_SSN);
verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
verify(mockUtkastRepository).save(any(Utkast.class));
verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
verify(userService).getUser();
verify(logService).logCreateIntyg(any(LogRequest.class));
verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
use of se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testReplaceIntyg.
@Test
public void testReplaceIntyg() {
final String personnummer = "191212121212";
final String newIntygId = "newIntygId";
CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
WebCertUser user = new WebCertUser();
addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_ERSATTA_INTYG);
user.setOrigin("NORMAL");
ArgumentCaptor<CreateReplacementCopyRequest> captor = ArgumentCaptor.forClass(CreateReplacementCopyRequest.class);
when(copyUtkastService.createReplacementCopy(captor.capture())).thenReturn(new CreateReplacementCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
when(webcertUserService.getUser()).thenReturn(user);
Response response = moduleApiController.createReplacement(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
verify(copyUtkastService).createReplacementCopy(any());
verifyNoMoreInteractions(copyUtkastService);
assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
}
Aggregations