Skip to content

Commit

Permalink
Merge pull request #458 from EsupPortail/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
dlemaignent authored Oct 2, 2024
2 parents 76e9983 + 09a4928 commit 662e42c
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public int countEmpty(String userEppn) {
}

@Transactional
public SignBook sendForSign(Long dataId, List<WorkflowStepDto> steps, List<String> targetEmails, List<String> targetUrls, String userEppn, String authUserEppn, boolean forceSendEmail, Map<String, String> formDatas, InputStream formReplaceInputStream, String signRequestParamsJsonString, String title, Boolean sendEmailAlert, String comment) throws EsupSignatureRuntimeException {
public SignBook sendForSign(Long dataId, List<WorkflowStepDto> steps, List<String> targetEmails, List<String> targetUrls, String userEppn, String authUserEppn, boolean forceSendEmail, Map<String, String> formDatas, InputStream formReplaceInputStream, String signRequestParamsJsonString, String title, Boolean sendEmailAlert, String comment) {
List<SignRequestParams> signRequestParamses = new ArrayList<>();
if (signRequestParamsJsonString != null) {
signRequestParamses = signRequestParamsService.getSignRequestParamsesFromJson(signRequestParamsJsonString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void addUserShare(User authUser, Boolean signWithOwnSign, Long[] form, Lo
}
Date beginDateDate = null;
Date endDateDate = null;
if (beginDate != null && endDate != null) {
if (StringUtils.hasText(beginDate) && StringUtils.hasText(endDate)) {
try {
beginDateDate = new SimpleDateFormat(DATE_PATTERN).parse(beginDate);
endDateDate = new SimpleDateFormat(DATE_PATTERN).parse(endDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Workflow createWorkflow(User user) {
}

@Transactional
public Workflow addStepToWorkflow(Long id, SignType signType, Boolean allSignToComplete, Boolean changeable, WorkflowStepDto step, User user, boolean recipientsRequired) throws EsupSignatureRuntimeException {
public Workflow addStepToWorkflow(Long id, SignType signType, Boolean allSignToComplete, Boolean changeable, WorkflowStepDto step, User user, boolean recipientsRequired) {
Workflow workflow;
if (id != null && id != -1) {
workflow = getById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,11 @@ public ResponseEntity<String> sendForm(@ModelAttribute("userEppn") String userEp
logger.info("create form " + id);
if(formService.isFormAuthorized(userEppn, authUserEppn, id)) {
Data data = dataService.addData(id, userEppn);
try {
SignBook signBook = signBookService.sendForSign(data.getId(), steps, targetEmails, null, userEppn, authUserEppn, false, null, null, null, null, true, null);
return ResponseEntity.ok().body(signBook.getId().toString());
} catch (EsupSignatureRuntimeException e) {
logger.warn(e.getMessage() + " for " + id);
}
} else {
logger.warn("form id " + id + " not autorized");
SignBook signBook = signBookService.sendForSign(data.getId(), steps, targetEmails, null, userEppn, authUserEppn, false, null, null, null, null, true, null);
return ResponseEntity.ok().body(signBook.getId().toString());
}
return ResponseEntity.internalServerError().body("Formulaire non autorisé");

logger.warn("form id " + id + " not autorized");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Formulaire non autorisé");
}

@PostMapping("/form/{id}")
Expand Down Expand Up @@ -111,7 +105,7 @@ public ResponseEntity<Void> getImagePdfAsByteArray(@PathVariable("id") Long id,
httpServletResponse.setContentType(MediaType.IMAGE_PNG_VALUE);
IOUtils.copy(in, httpServletResponse.getOutputStream());
in.close();
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,20 @@ public GetDataToSignResponse getDataToSign(@ModelAttribute("userEppn") String us
@ResponseBody
public ResponseEntity<?> signDocument(@ModelAttribute("userEppn") String userEppn, @ModelAttribute("authUserEppn") String authUserEppn,
@RequestBody @Valid SignResponse signatureValue,
@RequestParam("id") Long id) throws EsupSignatureRuntimeException, IOException {
@RequestParam("id") Long id) throws EsupSignatureRuntimeException, IOException, EsupSignatureException {
NexuSignature nexuSignature = nexuService.getNexuSignature(id);
AbstractSignatureForm abstractSignatureForm = nexuService.getAbstractSignatureFormFromNexuSignature(nexuSignature);
abstractSignatureForm.setSignatureValue(signatureValue.getSignatureValue());
SignDocumentResponse responseJson = null;
try {
responseJson = nexuService.getSignDocumentResponse(id, signatureValue, abstractSignatureForm, userEppn, nexuSignature.getDocumentToSign());
signRequestService.updateStatus(id, SignRequestStatus.signed, "Signature", null, "SUCCESS", null,null,null,null, userEppn, authUserEppn);
StepStatus stepStatus = signRequestService.applyEndOfSignRules(id, userEppn, authUserEppn, SignType.nexuSign, "");
if(stepStatus.equals(StepStatus.last_end)) {
signBookService.completeSignRequest(id, authUserEppn, "Tous les documents sont signés");
} else if (stepStatus.equals(StepStatus.completed)){
signBookService.pendingSignRequest(id, null, userEppn, authUserEppn, false);
}
nexuService.delete(id);
return ResponseEntity.ok().body(responseJson);
} catch (EsupSignatureException e) {
return ResponseEntity.internalServerError().body(e.getMessage());
}
SignDocumentResponse responseJson = nexuService.getSignDocumentResponse(id, signatureValue, abstractSignatureForm, userEppn, nexuSignature.getDocumentToSign());
signRequestService.updateStatus(id, SignRequestStatus.signed, "Signature", null, "SUCCESS", null,null,null,null, userEppn, authUserEppn);
StepStatus stepStatus = signRequestService.applyEndOfSignRules(id, userEppn, authUserEppn, SignType.nexuSign, "");
if(stepStatus.equals(StepStatus.last_end)) {
signBookService.completeSignRequest(id, authUserEppn, "Tous les documents sont signés");
} else if (stepStatus.equals(StepStatus.completed)){
signBookService.pendingSignRequest(id, null, userEppn, authUserEppn, false);
}
nexuService.delete(id);
return ResponseEntity.ok().body(responseJson);
}

@PostMapping(value = "/error")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,7 @@ public ResponseEntity<String> wizWorkflowSignAddStep(@ModelAttribute("userEppn")
if(steps.get(0).getUserSignFirst() != null && steps.get(0).getUserSignFirst()) {
signBookService.addUserSignFirstStep(signBookId, userEppn);
}
try {
signBookService.addNewStepToSignBook(signBookId, steps, authUserEppn);
} catch (EsupSignatureRuntimeException e) {
logger.debug(e.getMessage());
return ResponseEntity.internalServerError().build();
}
signBookService.addNewStepToSignBook(signBookId, steps, authUserEppn);
}
model.addAttribute("signBook", signBook);
model.addAttribute("close", close);
Expand Down Expand Up @@ -242,12 +237,7 @@ public ResponseEntity<String> wizXWorkflow(@PathVariable("workflowId") Long work
User user = (User) model.getAttribute("user");
final Context context = new Context(Locale.FRENCH);
Workflow workflow;
try {
workflow = workflowService.addStepToWorkflow(workflowId, steps.get(0).getSignType(), steps.get(0).getAllSignToComplete(), steps.get(0).getChangeable(), steps.get(0), user, false);
} catch (EsupSignatureRuntimeException e) {
logger.debug(e.getMessage());
return ResponseEntity.internalServerError().build();
}
workflow = workflowService.addStepToWorkflow(workflowId, steps.get(0).getSignType(), steps.get(0).getAllSignToComplete(), steps.get(0).getChangeable(), steps.get(0), user, false);
model.addAttribute("workflow", workflow);
model.asMap().forEach(context::setVariable);
if(end != null && end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand All @@ -36,23 +37,17 @@ public class ExportWsController {

@GetMapping(value = "/form/{name}/datas/csv", produces="text/csv")
@PreAuthorize("@wsAccessTokenService.isAllAccess(#xApiKey)")
public ResponseEntity<Void> getFormDatasCsv(@PathVariable String name, @ModelAttribute("xApiKey") @Parameter(hidden = true) String xApiKey, HttpServletResponse response) {
public ResponseEntity<Void> getFormDatasCsv(@PathVariable String name, @ModelAttribute("xApiKey") @Parameter(hidden = true) String xApiKey, HttpServletResponse response) throws IOException {
List<Form> forms = formRepository.findFormByNameAndDeletedIsNullOrDeletedIsFalse(name);
if (!forms.isEmpty()) {
try {
response.setContentType("text/csv; charset=utf-8");
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(forms.get(0).getName(), StandardCharsets.UTF_8) + ".csv");
InputStream csvInputStream = dataExportService.getCsvDatasFromForms(forms.stream().map(Form::getWorkflow).collect(Collectors.toList()));
IOUtils.copy(csvInputStream, response.getOutputStream());
return ResponseEntity.ok().build();
} catch (Exception e) {
logger.error("get file error", e);
}
} else {
logger.warn("form " + name + " not found");
return ResponseEntity.notFound().build();
response.setContentType("text/csv; charset=utf-8");
response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(forms.get(0).getName(), StandardCharsets.UTF_8) + ".csv");
InputStream csvInputStream = dataExportService.getCsvDatasFromForms(forms.stream().map(Form::getWorkflow).collect(Collectors.toList()));
IOUtils.copy(csvInputStream, response.getOutputStream());
return ResponseEntity.ok().build();
}
return ResponseEntity.internalServerError().build();
logger.warn("form " + name + " not found");
return ResponseEntity.notFound().build();
}

@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.esupportail.esupsignature.dto.WorkflowStepDto;
import org.esupportail.esupsignature.entity.Data;
import org.esupportail.esupsignature.entity.SignBook;
import org.esupportail.esupsignature.exception.EsupSignatureRuntimeException;
import org.esupportail.esupsignature.service.*;
import org.esupportail.esupsignature.service.export.DataExportService;
import org.slf4j.Logger;
Expand All @@ -27,6 +26,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -129,25 +129,20 @@ public ResponseEntity<?> start(@PathVariable Long id,
createByEppn = eppn;
}
if(createByEppn == null) {
throw new EsupSignatureRuntimeException("Required request parameter 'createByEppn' for method parameter type String is not present");
return ResponseEntity.badRequest().body("Required request parameter 'createByEppn' for method parameter type String is not present");
}
try {
Data data = dataService.addData(id, createByEppn);
TypeReference<Map<String, String>> type = new TypeReference<>(){};
Map<String, String> datas = new HashMap<>();
if(formDatas != null) {
datas = objectMapper.readValue(formDatas, type);
}
SignBook signBook = signBookService.sendForSign(data.getId(), recipientService.convertRecipientJsonStringToWorkflowStepDtos(stepsJsonString), targetEmails, targetUrls, createByEppn, createByEppn, true, datas, null, signRequestParamsJsonString, title, sendEmailAlert, comment);
signBookService.addViewers(signBook.getId(), recipientsCCEmails);
if(json) {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId());
} else {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId().toString());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.internalServerError().body("-1");
Data data = dataService.addData(id, createByEppn);
TypeReference<Map<String, String>> type = new TypeReference<>(){};
Map<String, String> datas = new HashMap<>();
if(formDatas != null) {
datas = objectMapper.readValue(formDatas, type);
}
SignBook signBook = signBookService.sendForSign(data.getId(), recipientService.convertRecipientJsonStringToWorkflowStepDtos(stepsJsonString), targetEmails, targetUrls, createByEppn, createByEppn, true, datas, null, signRequestParamsJsonString, title, sendEmailAlert, comment);
signBookService.addViewers(signBook.getId(), recipientsCCEmails);
if(json) {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId());
} else {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId().toString());
}
}

Expand Down Expand Up @@ -181,7 +176,7 @@ public ResponseEntity<?> startWithDoc(@PathVariable Long id,
@RequestParam(required = false) @Parameter(description = "Retour au format json (facultatif, false par défaut)") Boolean json,
@RequestParam(required = false) @Parameter(description = "commentaire") String comment,
@ModelAttribute("xApiKey") @Parameter(hidden = true) String xApiKey
) {
) throws IOException {
if(json == null) {
json = false;
}
Expand All @@ -192,22 +187,17 @@ public ResponseEntity<?> startWithDoc(@PathVariable Long id,
steps = recipientService.convertRecipientEmailsToStep(recipientEmails);
}
Data data = dataService.addData(id, createByEppn);
try {
TypeReference<Map<String, String>> type = new TypeReference<>(){};
Map<String, String> datas = new HashMap<>();
if(formDatas != null) {
datas.putAll(objectMapper.readValue(formDatas, type));
}
SignBook signBook = signBookService.sendForSign(data.getId(), steps, targetEmails, targetUrls, createByEppn, createByEppn, true, datas, multipartFiles[0].getInputStream(), signRequestParamsJsonString, title, sendEmailAlert, comment);
signRequestService.addAttachement(attachementMultipartFiles, null, signBook.getSignRequests().get(0).getId(), createByEppn);
if(json) {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId());
} else {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId().toString());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.internalServerError().body("-1");
TypeReference<Map<String, String>> type = new TypeReference<>(){};
Map<String, String> datas = new HashMap<>();
if(formDatas != null) {
datas.putAll(objectMapper.readValue(formDatas, type));
}
SignBook signBook = signBookService.sendForSign(data.getId(), steps, targetEmails, targetUrls, createByEppn, createByEppn, true, datas, multipartFiles[0].getInputStream(), signRequestParamsJsonString, title, sendEmailAlert, comment);
signRequestService.addAttachement(attachementMultipartFiles, null, signBook.getSignRequests().get(0).getId(), createByEppn);
if(json) {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId());
} else {
return ResponseEntity.ok(signBook.getSignRequests().get(0).getId().toString());
}
}

Expand Down
Loading

0 comments on commit 662e42c

Please sign in to comment.