Vyřešeno generování PDF pro podpis na základě entity, která se schvaluje.

closes #240
Verze_3.0
Josef Rokos 10 years ago
parent 05faa87071
commit 6db416dd04

@ -140,10 +140,11 @@ public class Constants {
public final static ReportMapping REPORTS[] = { public final static ReportMapping REPORTS[] = {
new ReportMapping(MOD_ADDRESSBOOK, new Report(1, false, "Adresní karty", "address")), 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_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_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_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"; public final static String REQTYPE_ORDER = "ORDER";

@ -1,5 +1,12 @@
package info.bukova.isspst; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -37,6 +44,46 @@ public class ModuleUtils {
return null; 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) { public static boolean isActive(String id) {
return getModule(id).isActive(); return getModule(id).isActive();

@ -14,6 +14,7 @@ import info.bukova.isspst.storage.DocumentFileStorage;
import org.hibernate.NonUniqueResultException; import org.hibernate.NonUniqueResultException;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.GenericTypeResolver;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -22,6 +23,7 @@ import javax.validation.Validator;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -40,8 +42,20 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
private DocumentFileStorage documentFileStorage; private DocumentFileStorage documentFileStorage;
private NumberSeriesService numberSeriesService; private NumberSeriesService numberSeriesService;
private Class<T> entityClass;
public AbstractService() {
entityClass = (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), AbstractService.class);
}
@Override
public List<Class<?>> getEntityClasses() {
List<Class<?>> classes = new ArrayList<Class<?>>();
classes.add(entityClass);
return classes;
}
public void setDocumentFileStorage(DocumentFileStorage storage) { public void setDocumentFileStorage(DocumentFileStorage storage) {
this.documentFileStorage = storage; this.documentFileStorage = storage;
} }

@ -23,5 +23,6 @@ public interface Service<T> {
public Module getModule(); public Module getModule();
public List<Report> getReports(); public List<Report> getReports();
public boolean canPrintRecord(T entity); public boolean canPrintRecord(T entity);
public List<Class<?>> getEntityClasses();
} }

@ -25,6 +25,7 @@ public interface RequirementBaseService<T extends RequirementBase> extends Servi
public void approve(T entity, Date approveDate); public void approve(T entity, Date approveDate);
public boolean canApprove(T entity); public boolean canApprove(T entity);
public List<User> getNextApprover(T entity); public List<User> getNextApprover(T entity);
public boolean prepareSignData(T entity, Date approveDate);
public List<T> getMy(); public List<T> getMy();

@ -1,7 +1,10 @@
package info.bukova.isspst.services.requirement; package info.bukova.isspst.services.requirement;
import info.bukova.isspst.Constants; 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.AuthItem;
import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.JobMapping;
import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.RequirementBase;
import info.bukova.isspst.data.RequirementState; 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.MailMessage;
import info.bukova.isspst.mail.Mailer; import info.bukova.isspst.mail.Mailer;
import info.bukova.isspst.mail.MessageBuilder; 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.AbstractOwnedService;
import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.LazyLoader;
import info.bukova.isspst.services.Service;
import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.settings.GlobalSettingsService;
import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService; 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.LazyInitializationException;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired; 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.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.ServletContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* @author Pepa Rokos * @author Pepa Rokos
@ -50,6 +63,16 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
private UserService userService; private UserService userService;
@Autowired @Autowired
protected WorkgroupService workgroupService; protected WorkgroupService workgroupService;
@Autowired
private ReportDefinition reportDefinition;
@Autowired
private ParamFiller paramFiller;
@Autowired
private GeneratorFactory genFactory;
@Autowired
private ServletContext servletContext;
@Autowired
private FileStorage storage;
@Override @Override
@Transactional @Transactional
@ -408,4 +431,53 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
return Constants.PERM_DELETE_NEW; 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<Object>) 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;
}
} }

@ -2,19 +2,19 @@ package info.bukova.isspst.services.tripbill;
import info.bukova.isspst.Constants; import info.bukova.isspst.Constants;
import info.bukova.isspst.StringUtils; import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.RequirementState;
import info.bukova.isspst.data.TripBill; import info.bukova.isspst.data.TripBill;
import info.bukova.isspst.data.TripBillApproval; import info.bukova.isspst.data.TripBillApproval;
import info.bukova.isspst.services.IsspstException; import info.bukova.isspst.services.IsspstException;
import info.bukova.isspst.services.requirement.RequirementBaseServiceImpl; import info.bukova.isspst.services.requirement.RequirementBaseServiceImpl;
import info.bukova.isspst.services.requirement.RequirementTypeService; import info.bukova.isspst.services.requirement.RequirementTypeService;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/** /**
* @author Pepa Rokos * @author Pepa Rokos
*/ */
@ -53,4 +53,9 @@ public class TripBillApprovalServiceImpl extends RequirementBaseServiceImpl<Trip
postAdd(entity); postAdd(entity);
} }
@Override
protected DataModel entityForReport(TripBillApproval entity) {
return entity.getBill();
}
} }

@ -4,12 +4,6 @@ import info.bukova.isspst.Constants;
import info.bukova.isspst.SessionData; import info.bukova.isspst.SessionData;
import info.bukova.isspst.StringUtils; import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.RequirementBase;
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.Service;
import info.bukova.isspst.services.requirement.ApproveException; import info.bukova.isspst.services.requirement.ApproveException;
import info.bukova.isspst.services.requirement.RequirementBaseService; import info.bukova.isspst.services.requirement.RequirementBaseService;
import info.bukova.isspst.signapi.SignData; import info.bukova.isspst.signapi.SignData;
@ -26,7 +20,6 @@ import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window; import org.zkoss.zul.Window;
import java.util.Date; import java.util.Date;
import java.util.UUID;
/** /**
* @author Pepa Rokos * @author Pepa Rokos
@ -39,12 +32,6 @@ public class ApproveDialogVM {
private Date approveDate; private Date approveDate;
@WireVariable @WireVariable
private SessionData sessionData; private SessionData sessionData;
@WireVariable
private ReportDefinition reportDefinition;
@WireVariable
private GeneratorFactory genFactory;
@WireVariable
private ParamFiller paramFiller;
private boolean signed; private boolean signed;
private boolean timer; private boolean timer;
@ -86,26 +73,10 @@ public class ApproveDialogVM {
@Command @Command
@NotifyChange("timer") @NotifyChange("timer")
public void signPdf() { public void signPdf() {
SignData data = new SignData(); if (service.prepareSignData(requirement, approveDate)) {
sessionData.setProperty(Constants.KEY_SIGN_DATA, data); timer = true;
data.setSignGuid(UUID.randomUUID().toString()); Executions.getCurrent().sendRedirect("/api/sign/signer.jnlp", "signer");
sessionData.setProperty(Constants.KEY_SIGN_GUID, data.getSignGuid()); }
// ToDo: Generovat report
reportDefinition.clear();
reportDefinition.setSingleObject(requirement);
reportDefinition.setReport(new Report(0, true, "", "tripRequirementApp", false, true, true));
reportDefinition.setService((Service) service);
paramFiller.fill();
Generator gen = genFactory.createGenerator(reportDefinition);
data.setPdfData(gen.generate());
data.setDescription(requirement.getDescription());
data.setNumser(requirement.getNumser());
timer = true;
Executions.getCurrent().sendRedirect("/api/sign/signer.jnlp", "signer");
} }
@Command @Command

Loading…
Cancel
Save