dg1cloud-core/pom.xml
.. .. @@ -68,7 +68,10 @@ 68 68 <artifactId>spring-boot-configuration-processor</artifactId> 69 69 <optional>true</optional> 70 70 </dependency> 71 -71 + <dependency>72 + <groupId>org.springframework.boot</groupId>73 + <artifactId>spring-boot-starter-mail</artifactId>74 + </dependency>72 75 <dependency> 73 76 <groupId>org.springframework.ws</groupId> 74 77 <artifactId>spring-ws-core</artifactId> .. .. @@ -136,9 +139,9 @@ 136 139 </includes> 137 140 </resource> 138 141 <resource> 139 - <directory>src/main/resource</directory>142 + <directory>src/main/resources</directory>140 143 <includes> 141 - <include>application.properties</include>144 + <include>**/*</include>142 145 </includes> 143 146 </resource> 144 147 </resources> dg1cloud-core/src/main/java/it/digione/dg1cloud/config/dg1cloud.properties
.. .. @@ -20,7 +20,7 @@ 20 20 google.recaptcha.key=6LfCHmkUAAAAAFa1KmVtPFecItBriBHx1qmKHcVS 21 21 google.recaptcha.secret=6LfCHmkUAAAAAKXdXWO36daHnItKQwkEvXOpX6YY 22 22 23 -isharedoc.ws.endpoint.instance=https://democorepa3.grupposistematica.it/isharedoc/webservices/webserviceInstance3.wsdl23 +isharedoc.ws.endpoint.instance=https://democorepa3.grupposistematica.it/isharedoc/webservices/instanceService3/24 24 isharedoc.ws.username=admin 25 25 isharedoc.ws.password=sistematica100 26 26 isharedoc.ws.urp.puid=0109 .. .. @@ -28,3 +28,13 @@ 28 28 isharedoc.ws.urp.storyboad=URP 29 29 isharedoc.ws.urp.metaviewname=URP 30 30 isharedoc.ws.urp.direction=IN 31 +isharedoc.ws.urp.transition=protocolla32 +#solo per le gbox (todo: implementare altre tipologie)33 +isharedoc.ws.urp.contacts[0].type=O34 +isharedoc.ws.urp.contacts[0].referenceType=GBOX35 +isharedoc.ws.urp.contacts[0].code=URP36 +isharedoc.ws.urp.contacts[1].type=T37 +isharedoc.ws.urp.contacts[1].referenceType=GBOX38 +isharedoc.ws.urp.contacts[1].code=URP39 +40 +isharedoc.ws.notification-from=Dg1Cloud notifiche sviluppo <no-reply@digione.eu>dg1cloud-core/src/main/java/it/digione/dg1cloud/controller/StartURPController.java
.. .. @@ -1,9 +1,18 @@ 1 1 package it.digione.dg1cloud.controller; 2 2 3 +import java.io.IOException;4 +import java.text.SimpleDateFormat;5 +6 +import javax.activation.DataHandler;7 +import javax.mail.internet.MimeMessage;3 8 import javax.validation.Valid; 4 9 import javax.xml.bind.JAXBElement; 5 10 11 +import org.slf4j.Logger;12 +import org.slf4j.LoggerFactory;6 13 import org.springframework.beans.factory.annotation.Autowired; 14 +import org.springframework.mail.javamail.JavaMailSender;15 +import org.springframework.mail.javamail.MimeMessageHelper;7 16 import org.springframework.stereotype.Controller; 8 17 import org.springframework.validation.BindingResult; 9 18 import org.springframework.web.bind.annotation.ControllerAdvice; .. .. @@ -13,18 +22,28 @@ 13 22 import org.springframework.web.servlet.ModelAndView; 14 23 15 24 import it.digione.dg1cloud.form.StartURPForm; 16 -import it.digione.dg1cloud.ws.client.SOAPConnector;17 -import it.digione.dg1cloud.ws.client.isd.IsdProperties;18 25 import it.digione.dg1cloud.ws.client.isd.IsdConfig; 26 +import it.digione.dg1cloud.ws.client.isd.IsdProperties;27 +import it.digione.dg1cloud.ws.client.isd.IsdSOAPConnector;19 28 import it.isharedoc.schemas.instance.InstanceMessageCreateRequest; 29 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest.Attachments;30 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest.Attachments.Attachment;31 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest.Contacts;32 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest.Contacts.Contact;33 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest.Variables;34 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest.Variables.Variable;35 +import it.isharedoc.schemas.instance.InstanceMessageCreateResponse;20 36 import it.isharedoc.schemas.instance.ObjectFactory; 21 37 22 38 @ControllerAdvice 23 39 @Controller 24 40 public class StartURPController { 25 41 42 + private static final Logger logger = LoggerFactory.getLogger(DownloadController.class);43 +26 44 @Autowired IsdProperties isdProperties; 27 45 @Autowired IsdConfig isdConfig; 46 + @Autowired JavaMailSender javaMailSender;28 47 29 48 @ModelAttribute("startURPForm") 30 49 public StartURPForm startURPForm() { .. .. @@ -40,22 +59,55 @@ 40 59 BindingResult result) { 41 60 42 61 ModelAndView modelAndView; 43 - if (result.hasErrors()){62 + //if (result.hasErrors()){63 + if (false) {44 64 modelAndView = new ModelAndView("startURP"); 45 65 modelAndView.addObject(result); 46 66 modelAndView.addObject("startURPForm", form); 47 - modelAndView.addObject("message", "Impossibbile inviare la richiesta");67 + modelAndView.addObject("message", "Impossibile inviare la richiesta");48 68 modelAndView.addObject("alertClass", "alert-danger"); 49 69 return modelAndView; 50 70 } else { 51 71 modelAndView = new ModelAndView("startURP"); 52 72 53 73 InstanceMessageCreateRequest imcr = createInstanceMessageCreateRequest(form); 54 - SOAPConnector soapConnector = isdConfig.soapConnector(isdConfig.marshaller(), isdConfig.wsSecurityInterceptor());55 - System.out.println(soapConnector.callWebService(soapConnector.getDefaultUri(), imcr));74 + IsdSOAPConnector soapConnector = isdConfig.soapConnector(isdConfig.marshaller(), isdConfig.wsSecurityInterceptor());56 75 57 - modelAndView.addObject("message", "Richiesta inviata con successo");58 - modelAndView.addObject("alertClass", "alert-success");76 + String numeroProtocollo = null;77 + String dataProtocollo = null;78 + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");79 + try {80 + InstanceMessageCreateResponse response = soapConnector.callWebService(soapConnector.getDefaultUri(), imcr);81 + numeroProtocollo = response.getIdentifier().getValue();82 + dataProtocollo = sdf.format(response.getIdentifierDate().getValue().toGregorianCalendar().getTime());83 + } catch (Exception e) {84 + logger.error("Errore invocazione servizi URP: " + e.getMessage(), e);85 + modelAndView.addObject(result);86 + modelAndView.addObject("startURPForm", form);87 + modelAndView.addObject("message", "Problemi nell'invio della richiesta: " + e.getMessage());88 + modelAndView.addObject("alertClass", "alert-danger");89 + return modelAndView;90 + }91 +92 + try {93 + MimeMessage message = javaMailSender.createMimeMessage();94 + MimeMessageHelper helper;95 + helper = new MimeMessageHelper(message, true);96 + helper.setSubject("Richiesta inviata correttamente al servizio URP");97 + helper.setFrom(isdProperties.getNotificationFrom());98 + helper.setTo(form.getMittente());99 + helper.setText("Richiesta inviata correttamente: " + numeroProtocollo + " del " + dataProtocollo, true);100 + javaMailSender.send(message);101 +102 + modelAndView.addObject("message", "Richiesta inviata con successo");103 + modelAndView.addObject("alertClass", "alert-success");104 + } catch (Exception e) {105 + modelAndView.addObject("message", "Richiesta inviata con successo, ma non รจ stato possibile inviare la conferma tramite email");106 + modelAndView.addObject("alertClass", "alert-warning");107 + }108 +109 + modelAndView.addObject("appIdentifier", numeroProtocollo);110 + modelAndView.addObject("appIdentifierDate", dataProtocollo);59 111 return modelAndView; 60 112 } 61 113 .. .. @@ -72,7 +124,68 @@ 72 124 request.setStoryboardCode(isdProperties.getUrp().getStoryboad()); 73 125 74 126 request.setMetaViewName(factory.createInstanceMessageCreateRequestMetaViewName(isdProperties.getUrp().getMetaviewname())); 127 + request.setDirection(isdProperties.getUrp().getDirection());75 128 76 - return null;129 + Contacts contacts = factory.createInstanceMessageCreateRequestContacts();130 +131 + Contact contact = new Contact();132 + contact.setDescription(factory.createInstanceMessageCreateRequestContactsContactDescription(startURPForm.getMittente()));133 + contact.setEmail(factory.createInstanceMessageCreateRequestContactsContactEmail( startURPForm.getMittente()));134 + contact.setType("F");135 + contact.setReferenceType("AB");136 + contact.setSearchType("EXTID");137 + contact.setSearchMode("NOTFOUNDDEF");138 + contact.setSearchValue(startURPForm.getMittente());139 +140 + contacts.getContact().add(contact);141 +142 + for ( it.digione.dg1cloud.ws.client.isd.IsdProperties.Urp.Contact urpContact : isdProperties.getUrp().getContacts() ) {143 + contact = new Contact();144 + contact.setType(urpContact.getType());145 + contact.setReferenceType(urpContact.getReferenceType());146 + contact.setSearchType("CODE");147 + contact.setSearchValue(urpContact.getCode());148 + contacts.getContact().add(contact);149 + }150 +151 + JAXBElement<Contacts> jaxbContacts = factory.createInstanceMessageCreateRequestContacts(contacts);152 + request.setContacts(jaxbContacts);153 +154 + JAXBElement<String> jaxbSubject = factory.createInstanceMessageCreateRequestSubject(startURPForm.getOggetto());155 + request.setSubject(jaxbSubject);156 +157 + JAXBElement<String> jaxbBody = factory.createInstanceMessageCreateRequestBody(startURPForm.getCorpo());158 + request.setBody(jaxbBody);159 +160 + Variable variable = new Variable();161 + variable.setKey("transition");162 + variable.setType("string");163 + variable.setValueString(factory.createInstanceMessageCreateRequestVariablesVariableValueString(isdProperties.getUrp().getTransition()));164 +165 + Variables variables = factory.createInstanceMessageCreateRequestVariables();166 + variables.getVariable().add(variable);167 + JAXBElement<Variables> jaxbVariables = factory.createInstanceMessageCreateRequestVariables(variables);168 +169 + request.setVariables(jaxbVariables);170 +171 + request.setStartWorkflow(factory.createInstanceMessageCreateRequestStartWorkflow(true));172 +173 + Attachments attachments = new Attachments();174 +175 + Attachment attachment = new Attachment();176 + attachment.setFilename( startURPForm.getAllegato().getOriginalFilename());177 + attachment.setContentType( factory.createInstanceMessageCreateRequestAttachmentsAttachmentContentType( startURPForm.getAllegato().getContentType()));178 + attachment.setFileset("isharedocMailAttach");179 + try {180 + attachment.setData(new DataHandler(startURPForm.getAllegato().getBytes(), startURPForm.getAllegato().getContentType()));181 + } catch (IOException e) {182 + throw new RuntimeException("Errore nella lettura dell'allegato da passare al servizio URP", e);183 + }184 + attachments.getAttachment().add(attachment);185 +186 + JAXBElement<Attachments> jaxbAttachments = factory.createInstanceMessageCreateRequestAttachments(attachments);187 + request.setAttachments(jaxbAttachments);188 +189 + return request;77 190 } 78 191 } dg1cloud-core/src/main/java/it/digione/dg1cloud/form/StartURPForm.java
.. .. @@ -1,5 +1,6 @@ 1 1 package it.digione.dg1cloud.form; 2 2 3 +import javax.validation.constraints.Email;3 4 import javax.validation.constraints.NotEmpty; 4 5 import javax.validation.constraints.NotNull; 5 6 .. .. @@ -10,6 +11,7 @@ 10 11 public class StartURPForm { 11 12 12 13 @NotEmpty 14 13 15 private String mittente; 14 16 @NotEmpty 15 17 private String oggetto; dg1cloud-core/src/main/java/it/digione/dg1cloud/ws/client/SOAPConnector.javadeleted file mode 100644
.. .. @@ -1,10 +0,0 @@ 1 -package it.digione.dg1cloud.ws.client;2 -3 -import org.springframework.ws.client.core.support.WebServiceGatewaySupport;4 -5 -public class SOAPConnector extends WebServiceGatewaySupport {6 -7 - public Object callWebService(String url, Object request){8 - return getWebServiceTemplate().marshalSendAndReceive(url, request);9 - }10 -}dg1cloud-core/src/main/java/it/digione/dg1cloud/ws/client/isd/IsdConfig.java
.. .. @@ -8,8 +8,6 @@ 8 8 import org.springframework.ws.client.support.interceptor.ClientInterceptor; 9 9 import org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor; 10 10 11 -import it.digione.dg1cloud.ws.client.SOAPConnector;12 -13 11 @Configuration 14 12 public class IsdConfig { 15 13 .. .. @@ -19,6 +17,7 @@ 19 17 public Jaxb2Marshaller marshaller() { 20 18 Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 21 19 marshaller.setContextPath("it.isharedoc.schemas.instance"); 20 + marshaller.setMtomEnabled(true);22 21 return marshaller; 23 22 } 24 23 .. .. @@ -30,12 +29,13 @@ 30 29 wss4jSecurityInterceptor.setSecurementPassword(isdProperties.getPassword()); 31 30 wss4jSecurityInterceptor.setSecurementPasswordType(WSConstants.PW_TEXT); 32 31 wss4jSecurityInterceptor.setSecurementUsernameTokenNonce(true); 32 + wss4jSecurityInterceptor.setSecurementUsernameTokenCreated(true);33 33 return wss4jSecurityInterceptor; 34 34 } 35 35 36 36 @Bean 37 - public SOAPConnector soapConnector(Jaxb2Marshaller marshaller, Wss4jSecurityInterceptor wsSecurityInterceptor) {38 - SOAPConnector client = new SOAPConnector();37 + public IsdSOAPConnector soapConnector(Jaxb2Marshaller marshaller, Wss4jSecurityInterceptor wsSecurityInterceptor) {38 + IsdSOAPConnector client = new IsdSOAPConnector();39 39 client.setDefaultUri(isdProperties.getEndpoint().getInstance()); 40 40 client.setMarshaller(marshaller); 41 41 client.setUnmarshaller(marshaller); dg1cloud-core/src/main/java/it/digione/dg1cloud/ws/client/isd/IsdProperties.java
.. .. @@ -1,5 +1,7 @@ 1 1 package it.digione.dg1cloud.ws.client.isd; 2 2 3 +import java.util.List;4 +3 5 import org.springframework.boot.context.properties.ConfigurationProperties; 4 6 import org.springframework.stereotype.Component; 5 7 .. .. @@ -11,6 +13,7 @@ 11 13 private Urp urp; 12 14 private String username; 13 15 private String password; 16 + private String notificationFrom;14 17 15 18 public Endpoint getEndpoint() { 16 19 return endpoint; .. .. @@ -36,11 +39,18 @@ 36 39 public void setPassword(String password) { 37 40 this.password = password; 38 41 } 42 + public String getNotificationFrom() {43 + return notificationFrom;44 + }45 + public void setNotificationFrom(String notificationFrom) {46 + this.notificationFrom = notificationFrom;47 + }39 48 @Override 40 49 public String toString() { 41 50 return "IsdProperties{" + 42 51 "username='" + username + "'," + 43 52 "endpoint=" + endpoint + "," + 53 + "notificationFrom=" + notificationFrom + "," +44 54 "urp=" + urp + 45 55 "}"; 46 56 } .. .. @@ -70,6 +80,9 @@ 70 80 private String storyboad; 71 81 private String metaviewname; 72 82 private String direction; 83 + private String transition;84 + private List<Contact> contacts;85 +73 86 public String getPuid() { 74 87 return puid; 75 88 } .. .. @@ -100,6 +113,18 @@ 100 113 public void setDirection(String direction) { 101 114 this.direction = direction; 102 115 } 116 + public String getTransition() {117 + return transition;118 + }119 + public void setTransition(String transition) {120 + this.transition = transition;121 + }122 + public List<Contact> getContacts() {123 + return contacts;124 + }125 + public void setContacts(List<Contact> contacts) {126 + this.contacts = contacts;127 + }103 128 @Override 104 129 public String toString() { 105 130 return "Urp{" + .. .. @@ -107,8 +132,43 @@ 107 132 "mbox='" + mbox + "'," + 108 133 "storyboad='" + storyboad + "'," + 109 134 "metaviewname='" + metaviewname + "'," + 110 - "direction='" + direction + "'" +135 + "direction='" + direction + "'," +136 + "transition='" + transition + "'," +137 + "contacts=" + contacts +111 138 "}"; 112 139 } 140 +141 + public static class Contact {142 + private String type;143 + private String referenceType;144 + private String code;145 +146 + public String getType() {147 + return type;148 + }149 + public void setType(String type) {150 + this.type = type;151 + }152 + public String getReferenceType() {153 + return referenceType;154 + }155 + public void setReferenceType(String referenceType) {156 + this.referenceType = referenceType;157 + }158 + public String getCode() {159 + return code;160 + }161 + public void setCode(String code) {162 + this.code = code;163 + }164 + @Override165 + public String toString() {166 + return "Contacts{" +167 + "type='" + type + "'," +168 + "referenceType='" + referenceType + "'," +169 + "code='" + code + "'" +170 + "}";171 + }172 + }113 173 } 114 174 } dg1cloud-core/src/main/java/it/digione/dg1cloud/ws/client/isd/IsdSOAPConnector.java
.. .. @@ -0,0 +1,24 @@ 1 +package it.digione.dg1cloud.ws.client.isd;2 +3 +import org.springframework.ws.client.core.support.WebServiceGatewaySupport;4 +import org.springframework.ws.soap.client.SoapFaultClientException;5 +6 +import it.isharedoc.schemas.instance.InstanceMessageCreateRequest;7 +import it.isharedoc.schemas.instance.InstanceMessageCreateResponse;8 +9 +public class IsdSOAPConnector extends WebServiceGatewaySupport {10 +11 + public InstanceMessageCreateResponse callWebService(String url, InstanceMessageCreateRequest request){12 + Object response = null;13 + try {14 + response = getWebServiceTemplate().marshalSendAndReceive(url, request);15 + } catch (SoapFaultClientException e) {16 + throw new RuntimeException(e.getFaultStringOrReason(), e);17 + }18 + if ( response instanceof InstanceMessageCreateResponse ) {19 + return (InstanceMessageCreateResponse) response;20 + } else {21 + throw new RuntimeException("Oggetto response di tipo errato -> " + response.getClass().getName() );22 + }23 + }24 +}dg1cloud-core/src/main/resources/application.properties
.. .. @@ -21,4 +21,12 @@ 21 21 22 22 logging.level.it.digione.dg1cloud=DEBUG 23 23 24 -logging.level.org.springframework.ws=TRACE24 +logging.level.org.springframework.ws=TRACE25 +26 +spring.mail.host=smtp.grupposistematica.it27 +spring.mail.username=support-erp28 +spring.mail.password=29 +#spring.mail.properties.mail.smtp.auth = true30 +#spring.mail.properties.mail.smtp.socketFactory.port = 46531 +#spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory32 +#spring.mail.properties.mail.smtp.socketFactory.fallback = falsedg1cloud-core/src/main/resources/templates/startURP.html
.. .. @@ -25,37 +25,45 @@ 25 25 method="post" role="form" 26 26 enctype="multipart/form-data" > 27 27 <div th:if="${message}" th:text="${message}" th:class="${'alert ' + alertClass}"></div> 28 - <div class="form-group">29 - <label for="mittente" class="control-label">Mittente*</label>30 - <input type="email" class="form-control" th:field="*{mittente}" required placeholder="Email mittente" />31 - <p th:if="${#fields.hasErrors('mittente')}">Email mittente mancante</p>28 + <div th:th:if="${appIdentifier}">29 + <div th:text="${'Protocollo ' + appIdentifier + ' del ' + appIdentifierDate}" th:class="${'alert alert-info'}"></div>30 + <div>31 + <p><a th:href="@{/startURP}" class="btn btn-link"><span th:text="${'Effettua una nuova richiesta'}"></span></a></p>32 + </div>32 33 </div> 33 - <div class="form-group">34 - <label for="oggetto" class="control-label">Oggetto*</label>35 - <input type="text" class="form-control" th:field="*{oggetto}" required />36 - <p th:if="${#fields.hasErrors('oggetto')}">Compilare l'oggetto della richiesta</p>37 - </div>38 - <div class="form-group">39 - <label for="oggetto" class="control-label">Richiesta*</label>40 - <textarea rows="5" class="form-control" th:field="*{corpo}" required ></textarea>41 - <p th:if="${#fields.hasErrors('corpo')}">Scrivere il corpo della richiesta</p>42 - </div>43 - <div class="form-group">44 - <label for="allegato" class="control-label">Allegato richiesta*</label>45 - <input type="file" class="form-control" th:field="*{allegato}" required ></input>46 - <p th:if="${#fields.hasErrors('allegato')}">Inserire un allegato</p>47 - <p class="error-message"48 - th:each="error: ${#fields.errors('allegato')}"49 - th:text="${error}"></p>50 - </div>51 - <div class="form-group">52 - <div class="g-recaptcha" th:attr="data-sitekey=${@captchaSettings.getKey()}"></div>53 - <p class="error-message"54 - th:each="error: ${#fields.errors('reCaptchaResponse')}"55 - th:text="'Errore validazione reCaptcha'"></p>56 - </div>57 - <div class="form-group">58 - <button name="Invia richiesta" type="submit" th:text="'Invia richiesta'"></button>34 + <div th:unless="${appIdentifier}">35 + <div class="form-group">36 + <label for="mittente" class="control-label">Mittente*</label>37 + <input type="email" class="form-control" th:field="*{mittente}" required placeholder="Email mittente" />38 + <p th:if="${#fields.hasErrors('mittente')}">Email mittente mancante</p>39 + </div>40 + <div class="form-group">41 + <label for="oggetto" class="control-label">Oggetto*</label>42 + <input type="text" class="form-control" th:field="*{oggetto}" required />43 + <p th:if="${#fields.hasErrors('oggetto')}">Compilare l'oggetto della richiesta</p>44 + </div>45 + <div class="form-group">46 + <label for="oggetto" class="control-label">Richiesta*</label>47 + <textarea rows="5" class="form-control" th:field="*{corpo}" required ></textarea>48 + <p th:if="${#fields.hasErrors('corpo')}">Scrivere il corpo della richiesta</p>49 + </div>50 + <div class="form-group">51 + <label for="allegato" class="control-label">Allegato richiesta*</label>52 + <input type="file" class="form-control" th:field="*{allegato}" required ></input>53 + <p th:if="${#fields.hasErrors('allegato')}">Inserire un allegato</p>54 + <p class="error-message"55 + th:each="error: ${#fields.errors('allegato')}"56 + th:text="${error}"></p>57 + </div>58 + <div class="form-group">59 + <div class="g-recaptcha" th:attr="data-sitekey=${@captchaSettings.getKey()}"></div>60 + <p class="error-message"61 + th:each="error: ${#fields.errors('reCaptchaResponse')}"62 + th:text="'Errore validazione reCaptcha'"></p>63 + </div>64 + <div class="form-group">65 + <button name="Invia richiesta" type="submit" th:text="'Invia richiesta'"></button>66 + </div>59 67 </div> 60 68 </form> 61 69 </div>