Skip to content

Commit

Permalink
Merge pull request #35 from EsupPortail/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
dlemaignent authored May 4, 2021
2 parents 0e0415a + ca8daef commit fa08b96
Show file tree
Hide file tree
Showing 30 changed files with 240 additions and 145 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<groupId>org.esupportail</groupId>
<artifactId>esup-signature</artifactId>
<version>1.12</version>
<version>1.12.1</version>
<name>esup-signature</name>
<properties>
<start-class>org.esupportail.esupsignature.EsupSignatureApplication</start-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CmisAccessImpl cmisAccessImpl(){
cmisAccessImpl.setLogin(fsProperties.getCmisLogin());
cmisAccessImpl.setPassword(fsProperties.getCmisPassword());
cmisAccessImpl.setRespositoryId(fsProperties.getCmisRespositoryId());
cmisAccessImpl.setRootPath(fsProperties.getCmisRootPath());
// cmisAccessImpl.setRootPath(fsProperties.getCmisRootPath());
return cmisAccessImpl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Form {

private String preFillType;

@ElementCollection
@ElementCollection(targetClass=String.class)
private List<String> roles = new ArrayList<>();

@ElementCollection(targetClass= ShareType.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Workflow {

private String updateBy;

@ElementCollection
@ElementCollection(targetClass=String.class)
private List<String> roles = new ArrayList<>();

@ElementCollection(targetClass= ShareType.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
import java.util.List;

public interface SignRequestRepository extends CrudRepository<SignRequest, Long>, PagingAndSortingRepository<SignRequest, Long>, SignRequestRepositoryCustom {
Long countById(Long id);
@Query("select distinct count(s) from SignRequest s join s.parentSignBook.liveWorkflow.currentStep.recipients r where s.status = 'pending' and r.user.eppn = :recipientUserEppn and r.signed = false")
Long countByRecipientUserToSign(@Param("recipientUserEppn") String recipientUserEppn);
List<SignRequest> findByIdIn(List<Long> ids);
List<SignRequest> findByToken(String token);
Long countByToken(String token);
@Query("select s from SignRequest s join s.parentSignBook.liveWorkflow.currentStep.recipients r where s.status = 'pending' and r.user.eppn = :recipientUserEppn and r.signed is false")
@Query("select distinct s from SignRequest s join s.parentSignBook.liveWorkflow.currentStep.recipients r where s.status = 'pending' and r.user.eppn = :recipientUserEppn and r.signed = false")
List<SignRequest> findByRecipientUserToSign(@Param("recipientUserEppn") String recipientUserEppn);
@Query("select count(s.id) from SignRequest s where s.status = 'pending' and key(s.recipientHasSigned).user.eppn = :recipientUserEppn and key(s.recipientHasSigned).signed = false")
Long countByRecipientUserToSign(@Param("recipientUserEppn") String recipientUserEppn);
List<SignRequest> findByCreateByEppn(String createByEppn);
List<SignRequest> findByCreateByEppnAndStatus(String createByEppn, SignRequestStatus status);
List<SignRequest> findByCreateByEppnAndStatusNot(String createByEppn, SignRequestStatus status);
Long countByCreateByEppnAndStatus(String createByEppn, SignRequestStatus status);
Page<SignRequest> findById(Long id, Pageable pageable);
Page<SignRequest> findAll(Pageable pageable);
Expand All @@ -38,5 +35,4 @@ public interface SignRequestRepository extends CrudRepository<SignRequest, Long>
SignRequest findSignRequestByCommentsContains(Comment comment);
List<SignRequest> findByTitle(String title);
List<SignRequest> findByParentSignBookTitle(String title);
List<SignRequest> findByStatus(SignRequestStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

@Repository
public interface PersonLdapLightRepository extends LdapRepository<PersonLdapLight> {
@Query(value = "(|(displayName={0}*)(cn={0}*)(uid={0}*)(mail={0}*))", countLimit = 9)

@Query(value = "(|(displayName={0}*)(cn={0}*)(uid={0})(mail={0}*))", countLimit = 9)
List<PersonLdapLight> fullTextSearch(String searchText);
}

Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public List<Data> getDatasByForm(Long formId) {
return dataRepository.findByFormId(formId);
}

public void delete(Long id) {
public void delete(Long id, String userEppn) {
Data data = getById(id);
if (data.getSignBook() != null) {
signBookService.delete(data.getSignBook().getId());
signBookService.delete(data.getSignBook().getId(), userEppn);
}
data.setForm(null);
dataRepository.delete(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ public Form createForm(Document document, String name, String title, Workflow wo
form.setDocument(document);
form.getTargets().addAll(targets);
form.getRoles().clear();
if(roleNames == null) roleNames = new ArrayList<>();
form.getRoles().addAll(roleNames);
form.setPreFillType(prefillType);
form.setWorkflow(workflow);
if(publicUsage == null) publicUsage = false;
form.setPublicUsage(publicUsage);
document.setParentId(form.getId());
if(testForms.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ public List<SignBook> getSharedSignBooks(String userEppn) {
// }

@Transactional
public void delete(Long signBookId) {
public void delete(Long signBookId, String userEppn) {
//TODO critères de suppression ou en conf (if deleteDefinitive)
SignBook signBook = getById(signBookId);
List<Long> signRequestsIds = signBook.getSignRequests().stream().map(SignRequest::getId).collect(Collectors.toList());
for(Long signRequestId : signRequestsIds) {
signRequestService.delete(signRequestId);
signRequestService.delete(signRequestId, userEppn);
}
signBook.setStatus(SignRequestStatus.deleted);
}
Expand Down Expand Up @@ -369,9 +369,12 @@ public void initWorkflowAndPendingSignBook(Long signRequestId, List<String> reci
importWorkflow(signBook, workflow, externalUsersInfos);
nextWorkFlowStep(signBook);
if(targetEmails != null && targetEmails.size() > 0) {
signBook.getLiveWorkflow().getTargets().clear();
StringBuilder targetEmailsToAdd = new StringBuilder();
for (String targetEmail : targetEmails) {
targetEmailsToAdd.append(targetEmail).append(";");
if(!targetEmailsToAdd.toString().contains(targetEmail)) {
targetEmailsToAdd.append(targetEmail.split("\\*")[1]).append(";");
}
}
signBook.getLiveWorkflow().getTargets().add(targetService.createTarget(DocumentIOType.mail, targetEmailsToAdd.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import eu.europa.esig.dss.model.x509.CertificateToken;
import eu.europa.esig.dss.spi.DSSUtils;
import eu.europa.esig.dss.token.Pkcs12SignatureToken;
import eu.europa.esig.dss.validation.reports.Reports;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.esupportail.esupsignature.config.GlobalProperties;
import org.esupportail.esupsignature.dss.model.AbstractSignatureForm;
import org.esupportail.esupsignature.dss.model.SignatureDocumentForm;
import org.esupportail.esupsignature.dss.model.SignatureMultipleDocumentsForm;
import org.esupportail.esupsignature.dss.service.FOPService;
import org.esupportail.esupsignature.entity.*;
import org.esupportail.esupsignature.entity.enums.*;
import org.esupportail.esupsignature.exception.*;
Expand Down Expand Up @@ -156,6 +158,12 @@ public class SignRequestService {
@Resource
private MessageSource messageSource;

@Resource
private ValidationService validationService;

@Resource
private FOPService fopService;

@PostConstruct
public void initSignrequestMetrics() {
customMetricsService.registerValue("esup-signature.signrequests", "new");
Expand All @@ -171,10 +179,6 @@ public SignRequest getById(long id) {
return signRequest;
}

public Long nbToSignSignRequests(String userEppn) {
return signRequestRepository.countByRecipientUserToSign(userEppn);
}

public List<SignRequest> getSignRequestsByToken(String token) {
return signRequestRepository.findByToken(token);
}
Expand Down Expand Up @@ -254,6 +258,10 @@ public Page<SignRequest> getSignRequestsByForm(Form form, Pageable pageable) {
return new PageImpl<>(signRequests.stream().skip(pageable.getOffset()).limit(pageable.getPageSize()).collect(Collectors.toList()), pageable, signRequests.size());
}

public Long nbToSignSignRequests(String userEppn) {
return signRequestRepository.countByRecipientUserToSign(userEppn);
}

public List<SignRequest> getToSignRequests(String userEppn) {
List<SignRequest> signRequestsToSign = signRequestRepository.findByRecipientUserToSign(userEppn);
signRequestsToSign = signRequestsToSign.stream().sorted(Comparator.comparing(SignRequest::getCreateDate).reversed()).collect(Collectors.toList());
Expand Down Expand Up @@ -408,10 +416,13 @@ public void afterCommit() {
}
});
return true;
} catch (EsupSignatureKeystoreException e) {
logger.error(e.getMessage());
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.error(e.getMessage());
return false;
}
return false;
}

@Transactional
Expand Down Expand Up @@ -932,14 +943,15 @@ public long generateUniqueId() {
}

@Transactional
public void delete(Long signRequestId) {
public void delete(Long signRequestId, String userEppn) {
//TODO critères de suppression ou en conf (if deleteDefinitive)
SignRequest signRequest = getById(signRequestId);
signRequest.getOriginalDocuments().clear();
if(signRequest.getStatus().equals(SignRequestStatus.exported) || signRequest.getStatus().equals(SignRequestStatus.archived)) {
signRequest.getSignedDocuments().clear();
}
signRequest.setStatus(SignRequestStatus.deleted);
logService.create(signRequest, SignRequestStatus.deleted, "DELETE", "", "SUCCESS", null, null, null, null, userEppn, userEppn);
otpService.deleteOtpBySignRequestId(signRequestId);
}

Expand Down Expand Up @@ -1173,6 +1185,9 @@ public void addStep(Long id, List<String> recipientsEmails, SignType signType, B

@Transactional
public Map<SignBook, String> sendSignRequest(MultipartFile[] multipartFiles, SignType signType, Boolean allSignToComplete, Boolean userSignFirst, Boolean pending, String comment, List<String> recipientsCCEmails, List<String> recipientsEmails, List<JsonExternalUserInfo> externalUsersInfos, User user, User authUser) throws EsupSignatureException, EsupSignatureIOException {
if (!signService.checkSignTypeDocType(signType, multipartFiles[0])) {
throw new EsupSignatureException("Impossible de demander une signature visuelle sur un document du type " + multipartFiles[0].getContentType());
}
SignBook signBook = signBookService.addDocsInNewSignBookSeparated("", "Demande simple", multipartFiles, user);
try {
signBookService.sendCCEmail(signBook.getId(), recipientsCCEmails);
Expand Down Expand Up @@ -1309,6 +1324,43 @@ public Map<String, Object> getToSignFileResponse(Long signRequestId) throws SQLE
}
}

@Transactional
public void getToSignFileReportResponse(Long signRequestId, HttpServletResponse response) throws Exception {
SignRequest signRequest = getById(signRequestId);
ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream());
String name = "";
InputStream inputStream = null;
if (!signRequest.getStatus().equals(SignRequestStatus.exported)) {
if(getToSignDocuments(signRequest.getId()).size() == 1) {
List<Document> documents = getToSignDocuments(signRequest.getId());
name = documents.get(0).getFileName();
inputStream = documents.get(0).getInputStream();
}
} else {
FsFile fsFile = getLastSignedFsFile(signRequest);
name = fsFile.getName();
inputStream = fsFile.getInputStream();
}

if(inputStream != null) {
byte[] fileBytes = inputStream.readAllBytes();

zipOutputStream.putNextEntry(new ZipEntry(name));
IOUtils.copy(new ByteArrayInputStream(fileBytes), zipOutputStream);
zipOutputStream.closeEntry();
File reportFile = fileService.getTempFile("report.pdf");

Reports reports = validationService.validate(new ByteArrayInputStream(fileBytes), null);

fopService.generateDetailedReport(reports.getXmlDetailedReport(), new FileOutputStream(reportFile));
zipOutputStream.putNextEntry(new ZipEntry("report.pdf"));
IOUtils.copy(new FileInputStream(reportFile), zipOutputStream);
zipOutputStream.closeEntry();
reportFile.delete();
}
zipOutputStream.close();
}

@Transactional
public Map<String, Object> getFileResponse(Long documentId) throws SQLException, EsupSignatureFsException, IOException {
Document document = documentService.getById(documentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.esupportail.esupsignature.entity.*;
import org.esupportail.esupsignature.entity.enums.*;
import org.esupportail.esupsignature.exception.EsupSignatureException;
import org.esupportail.esupsignature.exception.EsupSignatureRuntimeException;
import org.esupportail.esupsignature.exception.EsupSignatureUserException;
import org.esupportail.esupsignature.repository.WorkflowRepository;
import org.esupportail.esupsignature.service.interfaces.fs.FsAccessFactory;
Expand Down Expand Up @@ -257,9 +256,6 @@ public int importFilesFromSource(Long workflowId, User user, User authUser) {
if (fsAccessService.cd(workflow.getDocumentsSourceUri()) == null) {
logger.info("create non existing folders : " + workflow.getDocumentsSourceUri());
fsAccessService.createFile("/", workflow.getDocumentsSourceUri(), "folder");
if (fsAccessService.getFile("/" + workflow.getDocumentsSourceUri() + "/signed") == null) {
fsAccessService.createFile("/" + workflow.getDocumentsSourceUri() + "/", "signed", "folder");
}
}
try {
fsFiles.addAll(fsAccessService.listFiles(workflow.getDocumentsSourceUri() + "/"));
Expand Down Expand Up @@ -324,7 +320,7 @@ public int importFilesFromSource(Long workflowId, User user, User authUser) {
logger.info("aucun fichier à importer depuis : " + workflow.getDocumentsSourceUri());
}
} catch (Exception e) {
throw new EsupSignatureRuntimeException("error on import from " + workflow.getDocumentsSourceUri(), e);
logger.error("error on import from " + workflow.getDocumentsSourceUri());
}
fsAccessService.close();
} else {
Expand Down
Loading

0 comments on commit fa08b96

Please sign in to comment.