diff --git a/src/main/java/info/bukova/isspst/ModuleUtils.java b/src/main/java/info/bukova/isspst/ModuleUtils.java index 9596ea2e..b588358d 100644 --- a/src/main/java/info/bukova/isspst/ModuleUtils.java +++ b/src/main/java/info/bukova/isspst/ModuleUtils.java @@ -63,6 +63,8 @@ public class ModuleUtils { } } + continue; + } catch (ClassCastException e) { //nestandardní moduly neřeší... continue; } diff --git a/src/main/java/info/bukova/isspst/SpringUtils.java b/src/main/java/info/bukova/isspst/SpringUtils.java new file mode 100644 index 00000000..67c3050b --- /dev/null +++ b/src/main/java/info/bukova/isspst/SpringUtils.java @@ -0,0 +1,25 @@ +package info.bukova.isspst; + +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +import javax.servlet.ServletContext; + +/** + * @author Pepa Rokos + */ +public class SpringUtils { + + private static WebApplicationContext webCtx(ServletContext sc) { + return WebApplicationContextUtils.getRequiredWebApplicationContext(sc); + } + + public static Object getBean(String name, ServletContext sc) { + return webCtx(sc).getBean(name); + } + + public static T getBean(Class clazz, ServletContext sc) { + return webCtx(sc).getBean(clazz); + } + +} diff --git a/src/main/java/info/bukova/isspst/data/SignedDocument.java b/src/main/java/info/bukova/isspst/data/SignedDocument.java index 55190466..608aae43 100644 --- a/src/main/java/info/bukova/isspst/data/SignedDocument.java +++ b/src/main/java/info/bukova/isspst/data/SignedDocument.java @@ -3,19 +3,18 @@ package info.bukova.isspst.data; import info.bukova.isspst.Constants; import info.bukova.isspst.Module; import info.bukova.isspst.StringUtils; - -import java.util.Date; -import java.util.List; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; +import org.hibernate.search.annotations.IndexedEmbedded; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.OneToMany; import javax.persistence.Table; - -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; -import org.hibernate.search.annotations.IndexedEmbedded; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; @Entity @Table(name = "SIGNED_DOCUMENTS") @@ -105,6 +104,10 @@ public class SignedDocument extends BaseData { } public void addItem(SignedDocumentItem item) { + if (items == null) { + items = new ArrayList(); + } + item.setSignedDocument(this); this.items.add(item); } diff --git a/src/main/java/info/bukova/isspst/data/SignedDocumentItem.java b/src/main/java/info/bukova/isspst/data/SignedDocumentItem.java index 2e59e058..070c80a2 100644 --- a/src/main/java/info/bukova/isspst/data/SignedDocumentItem.java +++ b/src/main/java/info/bukova/isspst/data/SignedDocumentItem.java @@ -22,7 +22,7 @@ public class SignedDocumentItem { private int id; @Column(name = "REPORT_ID") - private int reportId; + private long reportId; @Column(name = "REPORT_NAME", length = Constants.LEN_TEXT) private String reportName; @@ -42,11 +42,11 @@ public class SignedDocumentItem { this.id = id; } - public int getReportId() { + public long getReportId() { return reportId; } - public void setReportId(int reportId) { + public void setReportId(long reportId) { this.reportId = reportId; } diff --git a/src/main/java/info/bukova/isspst/data/Workflow.java b/src/main/java/info/bukova/isspst/data/Workflow.java index ac489428..e6248890 100644 --- a/src/main/java/info/bukova/isspst/data/Workflow.java +++ b/src/main/java/info/bukova/isspst/data/Workflow.java @@ -1,15 +1,14 @@ package info.bukova.isspst.data; -import java.math.BigDecimal; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; - -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; +import java.math.BigDecimal; @Entity @Table(name = "WORKFLOW") @@ -24,7 +23,9 @@ public class Workflow extends BaseData { @Column(name = "WORDER") private Integer wOrder; @Column(name = "WLIMIT", precision=15, scale=4) - private BigDecimal limit; + private BigDecimal limit; + @Column(name = "SIGNATURE") + private Boolean signature; public Boolean getCentre() { return centre; @@ -68,4 +69,11 @@ public class Workflow extends BaseData { this.limit = limit; } + public Boolean getSignature() { + return signature; + } + + public void setSignature(Boolean signature) { + this.signature = signature; + } } diff --git a/src/main/java/info/bukova/isspst/reporting/ParamFiller.java b/src/main/java/info/bukova/isspst/reporting/ParamFiller.java index 41aec3b7..5ee150b8 100644 --- a/src/main/java/info/bukova/isspst/reporting/ParamFiller.java +++ b/src/main/java/info/bukova/isspst/reporting/ParamFiller.java @@ -74,7 +74,7 @@ public class ParamFiller { definition.setParam("P_PREV_APPROVER_SIGNATURE", storage.serverPath(prevApproverSettings.getSignatureFile())); } - AuthItem lastAuth = tb.getApproval().getAuthorization().get(tb.getRequirement().getAuthorization().size() - 1); + AuthItem lastAuth = tb.getApproval().getAuthorization().get(tb.getApproval().getAuthorization().size() - 1); definition.setParam("P_APPROVE_DATE", lastAuth.getAuthDate()); User u = lastAuth.getApprover(); diff --git a/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java b/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java index 8bfac506..a9579f02 100644 --- a/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java +++ b/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java @@ -1,18 +1,21 @@ package info.bukova.isspst.reporting; -import java.io.File; - -import javax.servlet.ServletContext; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import info.bukova.isspst.SpringUtils; +import info.bukova.isspst.data.DataModel; +import info.bukova.isspst.data.SignedDocumentItem; +import info.bukova.isspst.services.signeddocs.SignedDocumentService; +import info.bukova.isspst.storage.ReportFileStorage; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.JasperRunManager; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import net.sf.jasperreports.engine.util.JRLoader; import net.sf.jasperreports.engine.util.JRProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletContext; +import java.io.File; @SuppressWarnings("deprecation") public class PredefinedGenerator implements Generator { @@ -20,7 +23,7 @@ public class PredefinedGenerator implements Generator { private ReportDefinition definition; private ServletContext ctx; private final static Logger logger = LoggerFactory.getLogger(PredefinedGenerator.class); - + public PredefinedGenerator(ReportDefinition definition, ServletContext ctx) { this.definition = definition; this.ctx = ctx; @@ -29,7 +32,12 @@ public class PredefinedGenerator implements Generator { @Override public byte[] generate() { byte[] bytes = null; - + SignedDocumentItem signedItem = getSignedDocument(); + + if (signedItem != null) { + return fromStorage(signedItem); + } + try { JasperReport report = (JasperReport) JRLoader.loadObject(getReportFile()); JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250"); @@ -43,6 +51,18 @@ public class PredefinedGenerator implements Generator { return bytes; } + + private byte[] fromStorage(SignedDocumentItem sdItem) { + ReportFileStorage reportStorage = SpringUtils.getBean(ReportFileStorage.class, ctx); + return reportStorage.fileData(sdItem); + } + + private SignedDocumentItem getSignedDocument() { + SignedDocumentService sdService = SpringUtils.getBean(SignedDocumentService.class, ctx); + SignedDocumentItem sdItem = sdService.getItem((DataModel) definition.getDataSet().get(0), definition.getReport().getReportId()); + + return sdItem; + } protected File getReportFile() { return new File(ctx.getRealPath("WEB-INF/reports") + "/" + definition.getReport().getJasperFile() + ".jasper"); diff --git a/src/main/java/info/bukova/isspst/reporting/ReportController.java b/src/main/java/info/bukova/isspst/reporting/ReportController.java index 5e06b347..39c7e4e7 100644 --- a/src/main/java/info/bukova/isspst/reporting/ReportController.java +++ b/src/main/java/info/bukova/isspst/reporting/ReportController.java @@ -1,17 +1,17 @@ package info.bukova.isspst.reporting; -import java.io.IOException; -import java.io.OutputStream; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; - +import info.bukova.isspst.storage.ReportFileStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.OutputStream; + @Controller public class ReportController { @@ -21,6 +21,8 @@ public class ReportController { private GeneratorFactory factory; @Autowired private ParamFiller paramFiller; + @Autowired + private ReportFileStorage reportFileStorage; private static final String ERROR_MESSAGE = "Generator returned no data!
%s"; private final static Logger logger = LoggerFactory.getLogger(ReportController.class); @@ -46,13 +48,20 @@ public class ReportController { try { os = response.getOutputStream(); - if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) { + if ((reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) && reportDefinition.getSignedDocItem() == null) { throw new ReportException("Definition is null"); } - - paramFiller.fill(); - Generator gen = factory.createGenerator(reportDefinition); - byte[] data = gen.generate(); + + byte[] data; + + if (reportDefinition.getSignedDocItem() == null) { + paramFiller.fill(); + Generator gen = factory.createGenerator(reportDefinition); + data = gen.generate(); + } else { + data = reportFileStorage.fileData(reportDefinition.getSignedDocItem()); + } + response.setContentType(contentType); response.setContentLength(data.length); diff --git a/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java b/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java index b5a1b413..f6e0812d 100644 --- a/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java +++ b/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java @@ -1,5 +1,6 @@ package info.bukova.isspst.reporting; +import info.bukova.isspst.data.SignedDocumentItem; import info.bukova.isspst.services.Service; import java.io.Serializable; @@ -20,6 +21,7 @@ public class ReportDefinition implements Serializable { private List fieldsToPrint; private String reportTitle; private Service service; + private SignedDocumentItem signedDocItem; public ReportDefinition() { params = new HashMap(); @@ -92,6 +94,7 @@ public class ReportDefinition implements Serializable { reportTitle = ""; service = null; params.clear(); + signedDocItem = null; } public String getReportTitle() { @@ -110,4 +113,11 @@ public class ReportDefinition implements Serializable { this.service = service; } + public SignedDocumentItem getSignedDocItem() { + return signedDocItem; + } + + public void setSignedDocItem(SignedDocumentItem signedDocItem) { + this.signedDocItem = signedDocItem; + } } 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 588491f5..99b6834e 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -2,6 +2,7 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.User; +import info.bukova.isspst.data.Workflow; import info.bukova.isspst.services.Service; import java.util.Date; @@ -22,10 +23,11 @@ public interface RequirementBaseService extends Servi public void loadType(T data); public void loadWorkflow(T data); public void approve(T entity); - public void approve(T entity, Date approveDate); + public void approve(T entity, Date approveDate, byte[] signedPdf); public boolean canApprove(T entity); public List getNextApprover(T entity); public boolean prepareSignData(T entity, Date approveDate); + public Workflow getNextWorkflow(T entity); 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 d75f438c..753e344a 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -10,6 +10,8 @@ import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.SettingsData; +import info.bukova.isspst.data.SignedDocument; +import info.bukova.isspst.data.SignedDocumentItem; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workflow; import info.bukova.isspst.data.Workgroup; @@ -25,10 +27,12 @@ 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.signeddocs.SignedDocumentService; 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 info.bukova.isspst.storage.ReportFileStorage; import org.hibernate.LazyInitializationException; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; @@ -73,6 +77,10 @@ public abstract class RequirementBaseServiceImpl exte private ServletContext servletContext; @Autowired private FileStorage storage; + @Autowired + private SignedDocumentService signedDocumentService; + @Autowired + private ReportFileStorage signedDocStorage; @Override @Transactional @@ -142,6 +150,7 @@ public abstract class RequirementBaseServiceImpl exte workflow.setLimit(w.getLimit()); workflow.setOrder(w.getOrder()); workflow.setRole(w.getRole()); + workflow.setSignature(w.getSignature()); entity.getWorkflow().add(workflow); } } @@ -237,7 +246,7 @@ public abstract class RequirementBaseServiceImpl exte } } - protected void approve(T entity, User user, Date approveDate) { + protected void approve(T entity, User user, Date approveDate, byte[] signedPdf) { T e = (T) dao.getById(entity.getId()); if (e.getReqDate().getTime() > approveDate.getTime()) { @@ -269,6 +278,12 @@ public abstract class RequirementBaseServiceImpl exte super.update(e); + if (signedPdf != null) { + saveSignedDoc(e, signedPdf); + } else if (wf.getSignature() != null && wf.getSignature()) { + throw new ApproveException("ErrApproveMustBeSigned"); + } + if (!autoApprove(e, approveDate)) { this.sendToApprovers(e); @@ -296,7 +311,7 @@ public abstract class RequirementBaseServiceImpl exte } protected void approve(T entity, User user) { - approve(entity, user, new Date()); + approve(entity, user, new Date(), null); } @Override @@ -309,8 +324,8 @@ public abstract class RequirementBaseServiceImpl exte @Override @Transactional @PreAuthorize("this.canApprove(#entity)") - public void approve(T entity, Date approveDate) { - approve(entity, getLoggedInUser(), approveDate); + public void approve(T entity, Date approveDate, byte[] signedPdf) { + approve(entity, getLoggedInUser(), approveDate, signedPdf); } /** @@ -333,6 +348,30 @@ public abstract class RequirementBaseServiceImpl exte } + protected void saveSignedDoc(T entity, byte[] signedPdf) { + DataModel reportEntity = entityForSignReport(entity); + SignedDocumentItem signedItem = signedDocumentService.getItem(entityForSignReport(entity), getSignReport(entity).getReportId()); + + if (signedItem == null) { + SignedDocument signDoc = new SignedDocument(); + signDoc.setDescription(entity.getDescription()); + signDoc.setNumser(entity.getNumser()); + signDoc.setRecordId(reportEntity.getId()); + signDoc.setModuleName(ModuleUtils.getModule(reportEntity, servletContext).getId()); + signDoc.setSignDate(entity.getLastApproveDate()); + + SignedDocumentItem item = new SignedDocumentItem(); + item.setReportId(reportDefinition.getReport().getReportId()); + item.setReportName(reportDefinition.getReport().getName()); + signDoc.addItem(item); + + signedDocStorage.saveFile(signedPdf, item); + signedDocumentService.addFromApprove(signDoc); + } else { + signedDocStorage.saveFile(signedPdf, signedItem); + } + } + @Override @Transactional public boolean canApprove(T entity) { @@ -343,8 +382,12 @@ public abstract class RequirementBaseServiceImpl exte return false; } - - protected Workflow getNextWorkflow(T e) { + + @Override + @Transactional + public Workflow getNextWorkflow(T entity) { + T e = dao.getById(entity.getId()); + AuthItem authItem = null; if (e.getWorkflow() == null) { return null; @@ -439,23 +482,16 @@ public abstract class RequirementBaseServiceImpl exte sessionData.setProperty(Constants.KEY_SIGN_GUID, data.getSignGuid()); reportDefinition.clear(); - reportDefinition.setSingleObject(entityForReport(entity)); + reportDefinition.setSingleObject(entityForSignReport(entity)); - Module module = ModuleUtils.getModule(entityForReport(entity), servletContext); - Report report = null; - - for (Report r : module.getReports()) { - if (r.isSignable()) { - report = r; - break; - } - } + Report report = getSignReport(entity); if (report == null) { return false; } reportDefinition.setReport(report); + Module module = ModuleUtils.getModule(entityForSignReport(entity), servletContext); reportDefinition.setService((Service) ModuleUtils.getServiceInstance(module, servletContext)); paramFiller.fill(); @@ -464,6 +500,7 @@ public abstract class RequirementBaseServiceImpl exte data.setDescription(entity.getDescription()); data.setNumser(entity.getNumser()); data.setSignDate(approveDate); + data.setSigned(signedDocumentService.getItem(entityForSignReport(entity), report.getReportId()) != null); if (entity.getState() == RequirementState.NEW) { data.setAreaId(1); @@ -472,12 +509,28 @@ public abstract class RequirementBaseServiceImpl exte data.setAreaId(entity.getAuthorization().size() + 1); } - data.setSignImg(storage.fileData(userService.getUserSettings().getSignatureFile())); + if (userService.getUserSettings().getSignatureFile() != null) { + data.setSignImg(storage.fileData(userService.getUserSettings().getSignatureFile())); + } return true; } - protected DataModel entityForReport(T entity) { + protected DataModel entityForSignReport(T entity) { return entity; } + + private Report getSignReport(T entity) { + Module module = ModuleUtils.getModule(entityForSignReport(entity), servletContext); + Report report = null; + + for (Report r : module.getReports()) { + if (r.isSignable()) { + report = r; + break; + } + } + + return report; + } } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java index 1e33ee45..857857b0 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -60,7 +60,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl { + SignedDocument getForEntity(DataModel entity); + SignedDocumentItem getItem(DataModel entity, long reportId); + void addFromApprove(SignedDocument document); + } diff --git a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java index 8779dc3c..6550ade3 100644 --- a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java @@ -1,13 +1,25 @@ package info.bukova.isspst.services.signeddocs; +import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; +import info.bukova.isspst.data.DataModel; import info.bukova.isspst.data.SignedDocument; +import info.bukova.isspst.data.SignedDocumentItem; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; import org.hibernate.Hibernate; +import org.hibernate.Query; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.ServletContext; + public class SignedDocumentServiceImpl extends AbstractOwnedService implements SignedDocumentService { + + @Autowired + private ServletContext servletContext; + @LazyLoader("grid") @Transactional public void lazyLoadItems(SignedDocument signedDocument) { @@ -19,4 +31,45 @@ public class SignedDocumentServiceImpl extends AbstractOwnedService implements FileStorage { os.flush(); os.close(); } catch (FileNotFoundException e) { - e.printStackTrace(); + throw new StorageException("File cannot be found: " + file.getName(), e.getCause()); } catch (IOException e) { - e.printStackTrace(); + throw new StorageException("Cannot write file: " + file.getName(), e.getCause()); } finally { try { if (os != null) { diff --git a/src/main/java/info/bukova/isspst/storage/ReportFileStorage.java b/src/main/java/info/bukova/isspst/storage/ReportFileStorage.java new file mode 100644 index 00000000..e84a4451 --- /dev/null +++ b/src/main/java/info/bukova/isspst/storage/ReportFileStorage.java @@ -0,0 +1,10 @@ +package info.bukova.isspst.storage; + +import info.bukova.isspst.data.SignedDocumentItem; + +/** + * @author Pepa Rokos + */ +public interface ReportFileStorage extends FileStorage { + +} diff --git a/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java b/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java new file mode 100644 index 00000000..93f59998 --- /dev/null +++ b/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java @@ -0,0 +1,75 @@ +package info.bukova.isspst.storage; + +import info.bukova.isspst.data.SignedDocumentItem; + +import java.io.File; +import java.util.UUID; + +/** + * @author Pepa Rokos + */ +public class ReportFileStorageImpl extends AbstractFileStorage implements ReportFileStorage { + + private String rootPath; + + public void setRootPath(String rootPath) { + this.rootPath = rootPath; + } + + private String getFilePath(String fileName) { + return rootPath + "/" + fileName; + } + + @Override + public void saveFile(byte[] data, SignedDocumentItem signedDocumentItem) { + String fileName = signedDocumentItem.getFileName(); + + if (fileName == null) { + fileName = UUID.randomUUID().toString() + ".pdf"; + } + + saveFileDataToPath(data, getFilePath(fileName)); + signedDocumentItem.setFileName(fileName); + } + + @Override + public void saveFile(File file, SignedDocumentItem fileId) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeFile(SignedDocumentItem signedDocumentItem) { + removeFileByPath(getFilePath(signedDocumentItem.getFileName())); + } + + @Override + public void moveFile(String source, String destination) { + throw new UnsupportedOperationException(); + } + + @Override + public void createDirectory(String dir) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] fileData(SignedDocumentItem signedDocumentItem) { + return fileDataFromPath(getFilePath(signedDocumentItem.getFileName())); + } + + @Override + public File file(SignedDocumentItem signedDocumentItem) { + return null; + } + + @Override + public boolean dirExists(String path) { + return false; + } + + @Override + public String serverPath(SignedDocumentItem signedDocumentItem) { + return null; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/main/ApproveDialogVM.java b/src/main/java/info/bukova/isspst/ui/main/ApproveDialogVM.java index f0d1f897..3433900e 100644 --- a/src/main/java/info/bukova/isspst/ui/main/ApproveDialogVM.java +++ b/src/main/java/info/bukova/isspst/ui/main/ApproveDialogVM.java @@ -33,7 +33,9 @@ public class ApproveDialogVM { @WireVariable private SessionData sessionData; private boolean signed; + private boolean signRequired; private boolean timer; + private byte[] signedPdf; public Date getApproveDate() { return approveDate; @@ -52,14 +54,21 @@ public class ApproveDialogVM { this.grid = grid; this.approveDate = new Date(); - this.signed = false; + if (service.getNextWorkflow(requirement).getSignature() != null + && service.getNextWorkflow(requirement).getSignature()) { + this.signed = false; + this.signRequired = true; + } else { + this.signRequired = false; + } + this.timer = false; } @Command public void approve(@BindingParam("window") Window window) { try { - service.approve(requirement, approveDate); + service.approve(requirement, approveDate, signedPdf); BindUtils.postNotifyChange(null, null, grid, "dataBean"); BindUtils.postNotifyChange(null, null, grid, "canApprove"); BindUtils.postGlobalCommand(null, null, "reload", null); @@ -88,6 +97,7 @@ public class ApproveDialogVM { if (guid.equals(data.getSignGuid()) && data.isSignSuccess()) { signed = true; timer = false; + signedPdf = data.getPdfData(); } else { signed = false; } @@ -101,4 +111,7 @@ public class ApproveDialogVM { return timer; } + public boolean isSignRequired() { + return signRequired; + } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java b/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java index 279b8e7d..31a19d5a 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java @@ -6,13 +6,6 @@ import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Workflow; import info.bukova.isspst.services.requirement.RequirementTypeService; import info.bukova.isspst.services.users.RoleService; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.GlobalCommand; @@ -24,6 +17,12 @@ import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Listitem; import org.zkoss.zul.Window; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class RequirementTypesVM { @WireVariable @@ -236,6 +235,18 @@ public class RequirementTypesVM { Window win = (Window) Executions.createComponents("/settings/workflow/limit.zul", null, params); win.doModal(); } + + @Command + @NotifyChange({"selected", "centreSelWorkflow", "wgSelWorkflow"}) + public void toggleSignature(@BindingParam("workflow") Workflow workflow) { + if (workflow.getSignature() != null && workflow.getSignature()) { + workflow.setSignature(false); + } else { + workflow.setSignature(true); + } + + reqTypeService.update(selected); + } @GlobalCommand @NotifyChange("selected") diff --git a/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsList.java b/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsList.java index d5ee9511..2c2922ea 100644 --- a/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsList.java +++ b/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsList.java @@ -3,20 +3,22 @@ package info.bukova.isspst.ui.signeddocs; import info.bukova.isspst.data.SignedDocument; import info.bukova.isspst.data.SignedDocumentItem; import info.bukova.isspst.filters.SignedDocumentFilter; +import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.services.signeddocs.SignedDocumentService; import info.bukova.isspst.ui.ListViewModel; - -import java.util.ArrayList; -import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Listbox; +import org.zkoss.zul.Window; + +import java.util.ArrayList; +import java.util.List; public class SignedDocsList extends ListViewModel { @@ -30,6 +32,9 @@ public class SignedDocsList extends ListViewModel protected List signedDocumentItems; + @WireVariable + private ReportDefinition reportDefinition; + @Init(superclass = true) public void initSignedDocsList() { service = signedDocumentService; @@ -70,4 +75,12 @@ public class SignedDocsList extends ListViewModel this.signedDocumentItems = new ArrayList(); } } + + @Command + public void onOpen(@BindingParam("item") SignedDocumentItem item) { + reportDefinition.clear(); + reportDefinition.setSignedDocItem(item); + Window reportWin = (Window) Executions.createComponents("/app/reporting/report.zul", null, null); + reportWin.doModal(); + } } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 535c0d1b..1df6aba3 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -412,3 +412,7 @@ ForeignPersons = Cizí osoby TripBillResultMessageText = Zpráva z pracovní cesty ErrFillTripBillResultMessageText = Vyplňte zprávu z pracovní cesty. ErrFillTripBillResultTimes = Zadejte časy odjezdu a příjezdu. + +ErrApproveMustBeSigned = Schválení musí být digitálně podepsané. +DigitalSignature = Elektronický podpis +ContextMenu = Volby v kontextovém menu diff --git a/src/main/webapp/WEB-INF/reports/tripBill.jasper b/src/main/webapp/WEB-INF/reports/tripBill.jasper index 11f966a1..21e069c4 100644 Binary files a/src/main/webapp/WEB-INF/reports/tripBill.jasper and b/src/main/webapp/WEB-INF/reports/tripBill.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/tripBill.jrxml b/src/main/webapp/WEB-INF/reports/tripBill.jrxml index c51d0ef8..46bfe3cb 100644 --- a/src/main/webapp/WEB-INF/reports/tripBill.jrxml +++ b/src/main/webapp/WEB-INF/reports/tripBill.jrxml @@ -2,7 +2,7 @@ - + @@ -58,12 +58,6 @@ - - - - - - @@ -236,11 +230,13 @@ tuzemské pracovní cesty]]> - - - - - + + + + + + + @@ -427,12 +423,6 @@ tuzemské pracovní cesty]]> - - - - - - @@ -472,11 +462,6 @@ tuzemské pracovní cesty]]> - - - - - @@ -571,13 +556,6 @@ tuzemské pracovní cesty]]> - - - - - - - @@ -585,6 +563,18 @@ tuzemské pracovní cesty]]> + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/signer/PDFSigner.jar b/src/main/webapp/WEB-INF/signer/PDFSigner.jar index 665213cc..1b6cf795 100644 Binary files a/src/main/webapp/WEB-INF/signer/PDFSigner.jar and b/src/main/webapp/WEB-INF/signer/PDFSigner.jar differ diff --git a/src/main/webapp/WEB-INF/signer/PDFSignerWin.jar b/src/main/webapp/WEB-INF/signer/PDFSignerWin.jar index 0e6e45f3..651ef4ea 100644 Binary files a/src/main/webapp/WEB-INF/signer/PDFSignerWin.jar and b/src/main/webapp/WEB-INF/signer/PDFSignerWin.jar differ diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index a1057665..bfc9018f 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -183,6 +183,10 @@ + + + + diff --git a/src/main/webapp/WEB-INF/storage.properties b/src/main/webapp/WEB-INF/storage.properties index 3b71ef87..103f9058 100644 --- a/src/main/webapp/WEB-INF/storage.properties +++ b/src/main/webapp/WEB-INF/storage.properties @@ -1,2 +1,3 @@ storage.root=/home/pepa/tmp/isspst -storage.fulltextIndex=/home/pepa/tmp/isspst \ No newline at end of file +storage.fulltextIndex=/home/pepa/tmp/isspst +storage.signedDocuments=/home/pepa/tmp/isspst/signedDoc \ No newline at end of file diff --git a/src/main/webapp/img/sign-small.png b/src/main/webapp/img/sign-small.png new file mode 100644 index 00000000..8834f3f5 Binary files /dev/null and b/src/main/webapp/img/sign-small.png differ diff --git a/src/main/webapp/lists/signeddocs/grid.zul b/src/main/webapp/lists/signeddocs/grid.zul index 74b72e37..e361df43 100644 --- a/src/main/webapp/lists/signeddocs/grid.zul +++ b/src/main/webapp/lists/signeddocs/grid.zul @@ -1,5 +1,7 @@ - + + diff --git a/src/main/webapp/main/approveDialog.zul b/src/main/webapp/main/approveDialog.zul index cd803199..b4645ece 100644 --- a/src/main/webapp/main/approveDialog.zul +++ b/src/main/webapp/main/approveDialog.zul @@ -17,12 +17,12 @@