BrightSide Workbench Full Report + Source Code
DocumentPDF.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.financials.model.document.contract;
20 
21 import java.io.UnsupportedEncodingException;
22 import java.util.HashMap;
23 import javax.servlet.ServletContext;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import org.turro.string.ObjectString;
27 import org.turro.action.Actions;
28 import org.turro.auth.Authentication;
29 import org.turro.collections.KeyValueMap;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.elephant.context.IConstructor;
32 import org.turro.elephant.direct.DirectContent;
33 import org.turro.elephant.direct.DirectContents;
34 import org.turro.elephant.direct.IDirectContent;
35 import org.turro.elephant.security.IUser;
36 import org.turro.financials.db.FinancialsPU;
37 import org.turro.financials.entity.Document;
38 import org.turro.financials.model.document.GenerateDocument;
39 import org.turro.plugin.contacts.IContact;
40 
45 @DirectContent(identifier="document-pdf")
46 public class DocumentPDF implements IDirectContent {
47 
48  public static String createURL(IConstructor constructor, Document document) throws UnsupportedEncodingException, Exception {
50  if(contact != null && contact.isWebUser()) {
51  HashMap<String, String> values = new HashMap<>();
52  values.put(Actions.USER_PAR, contact.getConnector(IUser.CONNECTOR_EMAIL));
53  values.put("documentId", ObjectString.formatNativeObject(document.getId(), false));
55  DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
56  "?" + Actions.createAction(values, 7, false);
57  } else {
58  return "";
59  }
60  }
61 
62  public static String getIdentifier() {
63  return DocumentPDF.class.getAnnotation(DirectContent.class).identifier();
64  }
65 
66  @Override
67  public boolean itsMe(String id) {
68  return getIdentifier().equals(id);
69  }
70 
71  @Override
72  public boolean myTurn(HttpServletRequest request) {
73  return DirectContents.isYourTurn(request, getIdentifier());
74  }
75 
76  @Override
77  public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
78  IConstructor constructor = ElephantContext.getConstructor(request, response);
79  KeyValueMap map = Actions.getAction(constructor);
80  if(Actions.prepareActions(constructor, map)) {
81  Document document = new FinancialsPU().find(Document.class, Long.valueOf(map.get("documentId")));
83  gd.outputDocument(document, true, response);
84  }
85  }
86 
87 }
static String createAction(String email, String redir)
Definition: Actions.java:90
static final String USER_PAR
Definition: Actions.java:66
static KeyValueMap getAction(IConstructor constructor)
Definition: Actions.java:252
static boolean prepareActions(IConstructor constructor, KeyValueMap values)
Definition: Actions.java:173
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static boolean isYourTurn(HttpServletRequest request, String path)
void outputDocument(Document doc, boolean showValues, OutputStream out)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
static String createURL(IConstructor constructor, Document document)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27