From 6db416dd04a2994711a37bc76eedf6940eb4c7e2 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 3 Jul 2015 13:36:23 +0200 Subject: [PATCH] =?UTF-8?q?Vy=C5=99e=C5=A1eno=20generov=C3=A1n=C3=AD=20PDF?= =?UTF-8?q?=20pro=20podpis=20na=20z=C3=A1klad=C4=9B=20entity,=20kter=C3=A1?= =?UTF-8?q?=20se=20schvaluje.=20closes=20#240?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/info/bukova/isspst/Constants.java | 5 +- .../java/info/bukova/isspst/ModuleUtils.java | 47 ++++++++++++ .../isspst/services/AbstractService.java | 14 ++++ .../info/bukova/isspst/services/Service.java | 1 + .../requirement/RequirementBaseService.java | 1 + .../RequirementBaseServiceImpl.java | 72 +++++++++++++++++++ .../tripbill/TripBillApprovalServiceImpl.java | 11 ++- .../isspst/ui/main/ApproveDialogVM.java | 37 ++-------- 8 files changed, 150 insertions(+), 38 deletions(-) diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 002fa378..44040098 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -140,10 +140,11 @@ public class Constants { public final static ReportMapping REPORTS[] = { new ReportMapping(MOD_ADDRESSBOOK, new Report(1, false, "Adresní karty", "address")), new ReportMapping(MOD_ADDRESSBOOK, new Report(2, false, "Adresa", "address", false, true)), - new ReportMapping(MOD_TRIPBILL, new Report(3, true, "Žádost", "tripRequirement", false, true)), + new ReportMapping(MOD_TRIPBILL, new Report(3, false, "Žádost", "tripRequirement", false, true)), new ReportMapping(MOD_TRIPBILL, new Report(4, true, "Vyúčtování", "tripBill", false, true, true)), new ReportMapping(MOD_ORDER, new Report(5, false, "Objednávka", "order", true, true)), - new ReportMapping(MOD_REQUIREMENTS, new Report(6, false, "Požadavky", "requirements")) + new ReportMapping(MOD_REQUIREMENTS, new Report(6, false, "Požadavky", "requirements")), + new ReportMapping(MOD_TRIPREQUIREMENTS, new Report(7, true, "Žádost o SC", "tripRequirementApp", false, true)) }; public final static String REQTYPE_ORDER = "ORDER"; diff --git a/src/main/java/info/bukova/isspst/ModuleUtils.java b/src/main/java/info/bukova/isspst/ModuleUtils.java index f527063b..9596ea2e 100644 --- a/src/main/java/info/bukova/isspst/ModuleUtils.java +++ b/src/main/java/info/bukova/isspst/ModuleUtils.java @@ -1,5 +1,12 @@ package info.bukova.isspst; +import info.bukova.isspst.data.DataModel; +import info.bukova.isspst.services.Service; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +import javax.servlet.ServletContext; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -37,6 +44,46 @@ public class ModuleUtils { return null; } + + public static Module getModule(DataModel entity, ServletContext sc) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); + for (Module m : Constants.MODULES) { + Service service; + + try { + service = (Service) ctx.getBean(m.getServiceClass()); + } catch (NoSuchBeanDefinitionException e) { + String[] beans = ctx.getBeanNamesForType(m.getServiceClass()); + + for (String s : beans) { + service = (Service) ctx.getBean(s); + + if (service.getEntityClasses().contains(entity.getClass())) { + return m; + } + } + + continue; + } + + if (service.getEntityClasses().contains(entity.getClass())) { + return m; + } + } + + return null; + } + + public static Service getServiceInstance(Module m, ServletContext sc) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); + + try { + return (Service) ctx.getBean(m.getServiceClass()); + } catch (NoSuchBeanDefinitionException e) { + String[] beans = ctx.getBeanNamesForType(m.getServiceClass()); + return (Service) ctx.getBean(beans[0]); + } + } public static boolean isActive(String id) { return getModule(id).isActive(); diff --git a/src/main/java/info/bukova/isspst/services/AbstractService.java b/src/main/java/info/bukova/isspst/services/AbstractService.java index 613a57e8..b199d869 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractService.java @@ -14,6 +14,7 @@ import info.bukova.isspst.storage.DocumentFileStorage; import org.hibernate.NonUniqueResultException; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.GenericTypeResolver; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -22,6 +23,7 @@ import javax.validation.Validator; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -40,8 +42,20 @@ public abstract class AbstractService implements Service private DocumentFileStorage documentFileStorage; private NumberSeriesService numberSeriesService; + private Class entityClass; + public AbstractService() { + entityClass = (Class) GenericTypeResolver.resolveTypeArgument(getClass(), AbstractService.class); + } + + @Override + public List> getEntityClasses() { + List> classes = new ArrayList>(); + classes.add(entityClass); + return classes; + } + public void setDocumentFileStorage(DocumentFileStorage storage) { this.documentFileStorage = storage; } diff --git a/src/main/java/info/bukova/isspst/services/Service.java b/src/main/java/info/bukova/isspst/services/Service.java index 8285e0ec..0a4c3d15 100644 --- a/src/main/java/info/bukova/isspst/services/Service.java +++ b/src/main/java/info/bukova/isspst/services/Service.java @@ -23,5 +23,6 @@ public interface Service { public Module getModule(); public List getReports(); public boolean canPrintRecord(T entity); + public List> getEntityClasses(); } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java index 27407beb..588491f5 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -25,6 +25,7 @@ public interface RequirementBaseService extends Servi public void approve(T entity, Date approveDate); public boolean canApprove(T entity); public List getNextApprover(T entity); + public boolean prepareSignData(T entity, Date approveDate); public List getMy(); diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java index f8e30263..d75f438c 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -1,7 +1,10 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.Constants; +import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; import info.bukova.isspst.data.AuthItem; +import info.bukova.isspst.data.DataModel; import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.RequirementState; @@ -13,11 +16,19 @@ import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.mail.MailMessage; import info.bukova.isspst.mail.Mailer; import info.bukova.isspst.mail.MessageBuilder; +import info.bukova.isspst.reporting.Generator; +import info.bukova.isspst.reporting.GeneratorFactory; +import info.bukova.isspst.reporting.ParamFiller; +import info.bukova.isspst.reporting.Report; +import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; +import info.bukova.isspst.services.Service; import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.signapi.SignData; +import info.bukova.isspst.storage.FileStorage; import org.hibernate.LazyInitializationException; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; @@ -25,9 +36,11 @@ import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.ServletContext; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.UUID; /** * @author Pepa Rokos @@ -50,6 +63,16 @@ public abstract class RequirementBaseServiceImpl exte private UserService userService; @Autowired protected WorkgroupService workgroupService; + @Autowired + private ReportDefinition reportDefinition; + @Autowired + private ParamFiller paramFiller; + @Autowired + private GeneratorFactory genFactory; + @Autowired + private ServletContext servletContext; + @Autowired + private FileStorage storage; @Override @Transactional @@ -408,4 +431,53 @@ public abstract class RequirementBaseServiceImpl exte return Constants.PERM_DELETE_NEW; } + @Override + public boolean prepareSignData(T entity, Date approveDate) { + SignData data = new SignData(); + sessionData.setProperty(Constants.KEY_SIGN_DATA, data); + data.setSignGuid(UUID.randomUUID().toString()); + sessionData.setProperty(Constants.KEY_SIGN_GUID, data.getSignGuid()); + + reportDefinition.clear(); + reportDefinition.setSingleObject(entityForReport(entity)); + + Module module = ModuleUtils.getModule(entityForReport(entity), servletContext); + Report report = null; + + for (Report r : module.getReports()) { + if (r.isSignable()) { + report = r; + break; + } + } + + if (report == null) { + return false; + } + + reportDefinition.setReport(report); + reportDefinition.setService((Service) ModuleUtils.getServiceInstance(module, servletContext)); + + paramFiller.fill(); + Generator gen = genFactory.createGenerator(reportDefinition); + data.setPdfData(gen.generate()); + data.setDescription(entity.getDescription()); + data.setNumser(entity.getNumser()); + data.setSignDate(approveDate); + + if (entity.getState() == RequirementState.NEW) { + data.setAreaId(1); + } else { + loadAuthItems(entity); + data.setAreaId(entity.getAuthorization().size() + 1); + } + + data.setSignImg(storage.fileData(userService.getUserSettings().getSignatureFile())); + + return true; + } + + protected DataModel entityForReport(T entity) { + return entity; + } } diff --git a/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java b/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java index c9827168..b5fbf44b 100644 --- a/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillApprovalServiceImpl.java @@ -2,19 +2,19 @@ package info.bukova.isspst.services.tripbill; import info.bukova.isspst.Constants; import info.bukova.isspst.StringUtils; +import info.bukova.isspst.data.DataModel; import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.TripBill; import info.bukova.isspst.data.TripBillApproval; import info.bukova.isspst.services.IsspstException; import info.bukova.isspst.services.requirement.RequirementBaseServiceImpl; import info.bukova.isspst.services.requirement.RequirementTypeService; - -import java.util.Date; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; + /** * @author Pepa Rokos */ @@ -53,4 +53,9 @@ public class TripBillApprovalServiceImpl extends RequirementBaseServiceImpl