org.cristalise.restapi.ItemWorkflow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cristalise-restapi Show documentation
Show all versions of cristalise-restapi Show documentation
CRISTAL-iSE REST API Module
/**
* This file is part of the CRISTAL-iSE REST API.
* Copyright (c) 2001-2016 The CRISTAL Consortium. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* http://www.fsf.org/licensing/licenses/lgpl.html
*/
package org.cristalise.restapi;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.ws.rs.CookieParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.cristalise.kernel.graph.model.Vertex;
import org.cristalise.kernel.lifecycle.instance.Activity;
import org.cristalise.kernel.lifecycle.instance.CompositeActivity;
import org.cristalise.kernel.lifecycle.instance.Next;
import org.cristalise.kernel.lifecycle.instance.Workflow;
import org.cristalise.kernel.process.Gateway;
import org.cristalise.kernel.utils.Logger;
import org.json.XML;
@Path("/item/{uuid}/workflow")
public class ItemWorkflow extends ItemUtils {
private Map getGanttTask(String uuid, String parent, Activity act) {
LinkedHashMap aTask = new LinkedHashMap();
if (parent == null) {
aTask.put("id", uuid);
aTask.put("type", "project");
aTask.put("text", getProxy(uuid).getName());
aTask.put("open", true);
aTask.put("duration", "");
aTask.put("start_date", "");
}
else {
aTask.put("id", uuid + "/" + act.getID());
aTask.put("parent", parent);
aTask.put("type", "task");
aTask.put("text", act.getTypeName());
Integer duration = (Integer)act.getProperties().get("Duration");
aTask.put("duration", BigDecimal.valueOf(duration/3600.00));
aTask.put("start_date", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
}
return aTask;
}
private Map getGanttLink(String uuid, Next edge) {
Map aLink = new LinkedHashMap();
aLink.put("id", uuid + "/" + edge.getID());
aLink.put("source", uuid + "/" + edge.getOriginVertexId());
aLink.put("target", uuid + "/" + edge.getTerminusVertexId());
aLink.put("type", "0");
return aLink;
}
//FIXME: use Script or injected implementation (each gantt utility can have different json representation)
private Map getGanttObject(Workflow wf) throws Exception {
CompositeActivity domain = (CompositeActivity) wf.search("workflow/domain");
LinkedHashMap ganttObject = new LinkedHashMap();
ArrayList