+++ /dev/null
-/**
- *
- */
-package fr.mbdx.service;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.zip.ZipOutputStream;
-
-import javax.xml.bind.JAXBException;
-
-import org.activiti.engine.ProcessEngine;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.activiti.engine.task.Task;
-import org.alfresco.cmis.client.AlfrescoDocument;
-import org.apache.chemistry.opencmis.client.api.Document;
-import org.apache.chemistry.opencmis.client.api.Property;
-import org.apache.chemistry.opencmis.commons.data.ContentStream;
-import org.apache.log4j.Logger;
-
-import fr.mbdx.ixbus.client.Attachment;
-import fr.mbdx.ixbus.client.ClientException;
-import fr.mbdx.ixbus.client.impl.AttachmentCfxImpl;
-import fr.mbdx.ixbus.client.impl.Utils;
-
-public class ServiceUrbanisme {
-
- protected Logger log = Logger.getLogger(getClass());
-
- private ProcessEngine processEngine;
- private Utils utils;
-
- private String activitiHost;
- private String activitiPort;
- private String activitiProtocol;
-
- /**
- * Retourne un URL pointant directement vers la tâche affectée à l'utilisateur en cours au sein d'Activiti Explorer
- * Il a la forme suivante : http://localhost:8180/activiti-explorer/ui/#tasks/115034?category=inbox
- * @param execution
- * @param taskDefinitionKey
- * @param assignee
- * @return
- */
- public String getUserTaskUrl(DelegateExecution execution, String taskDefinitionKey, String assignee) {
- Task result = processEngine.getTaskService().createTaskQuery()
- .taskAssignee(assignee)
- .executionId(execution.getId())
- .taskDefinitionKey(taskDefinitionKey)
- .singleResult();
-
- String port = activitiPort.equals("80") ? "" : ":" + activitiPort;
- String task = result != null ? "/" + result.getId() : "";
- String url = activitiProtocol + "://" + activitiHost + port + "/activiti-explorer/#tasks" + task + "?category=inbox";
-
- return url;
- }
-
- /**
- * Crée une pièce jointe iXbus à partir du contenu d'un dossier d'urbanisme
- *
- * @param list
- * @param mainDocument
- * @return
- * @throws ClientException
- * @throws IOException
- * @throws JAXBException
- */
- public Attachment createPjFromList(List<Document> list, Document mainDocument) throws ClientException, IOException, JAXBException {
- Attachment attach = null;
- ByteArrayOutputStream baos = null;
- ZipOutputStream zos = null;
- List<String> annexes = new ArrayList<String>();
- int count = 0;
-
- try {
- baos = new ByteArrayOutputStream();
- zos = new ZipOutputStream(baos);
-
- String mainDocumentUniqueFileName = null;
- for (Document obj : list) {
- AlfrescoDocument doc = (AlfrescoDocument) obj;
- Property<?> envoiTdTProp = doc.getProperty("mbdx:envoiTdT");
- if (envoiTdTProp != null) {
- boolean envoiTdT = (Boolean) envoiTdTProp.getValue();
- if (envoiTdT) {
- count++;
- ContentStream contentStream = doc.getContentStream();
- InputStream is = contentStream.getStream();
- String filename = contentStream.getFileName();
- String uniqueFileName = utils.getUniqueFileName(filename);
- log.info("Création pièce jointe " + uniqueFileName);
- utils.putEntryIntoZipOutputStream(zos, is, uniqueFileName);
-
- //On joint le document à la liste d'annexes (sauf le document principal)
- if (doc.getId().equals(mainDocument.getId())) {
- mainDocumentUniqueFileName = uniqueFileName;
- } else {
- annexes.add(uniqueFileName);
- }
- }
- }
- }
-
- if (mainDocumentUniqueFileName != null) {
- String attachmentDescription = utils.createAttachmentDescription(mainDocumentUniqueFileName, annexes);
- zos.setComment(attachmentDescription);
- zos.finish();
- attach = new AttachmentCfxImpl();
- byte[] bytes = baos.toByteArray();
- attach.setContent(bytes);
- attach.setSize(bytes.length);
- }
-
- } finally {
- if (count > 0) {
- if (baos != null) {
- baos.close();
- }
- if (zos != null) {
- zos.close();
- }
- } else {
- log.warn("Aucun document marqué \"Bon pour le TdT\" n'a été trouvé dans ce dossier !");
- }
- }
-
- return attach;
- }
-
- public String getCartadsUrl(String nodeRef) {
- log.warn("La fonction getCartadsUrl doit encore être implémentée !");
- return "http://teleportail.bull.fr";
- }
-
- /**
- * Déclenche un événément Cart@ds sur un document Alfresco
- * TODO à implémenter quand on aura les specs du webservice Cart@ds
- * @param nodeRef référence Alfresco du document à traiter
- */
- public void triggerCartadsEvent(String nodeRef) {
- log.warn("La fonction triggerCartadsEvent doit encore être implémentée !");
- }
-
- /**
- * @param activitiHost the activitiHost to set
- */
- public void setActivitiHost(String activitiHost) {
- this.activitiHost = activitiHost;
- }
- /**
- * @param activitiPort the activitiPort to set
- */
- public void setActivitiPort(String activitiPort) {
- this.activitiPort = activitiPort;
- }
- /**
- * @param activitiProtocol the activitiProtocol to set
- */
- public void setActivitiProtocol(String activitiProtocol) {
- this.activitiProtocol = activitiProtocol;
- }
-
- /**
- * @param utils the utils to set
- */
- public void setUtils(Utils utils) {
- this.utils = utils;
- }
-
- /**
- * @param processEngine the processEngine to set
- */
- public void setProcessEngine(ProcessEngine processEngine) {
- this.processEngine = processEngine;
- }
-
-}