Skip to content
Snippets Groups Projects
Commit c808a2d7 authored by Mike McKay's avatar Mike McKay
Browse files

Reverted a change that was causing the pipelines tab not to load.

parent 30c2f1ae
Branches
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ package org.nrg.xnat.restlet.resources; ...@@ -13,7 +13,6 @@ package org.nrg.xnat.restlet.resources;
import org.nrg.pipeline.PipelineRepositoryManager; import org.nrg.pipeline.PipelineRepositoryManager;
import org.nrg.xdat.om.ArcProject; import org.nrg.xdat.om.ArcProject;
import org.nrg.xdat.om.PipePipelinerepository;
import org.nrg.xdat.om.XnatProjectdata; import org.nrg.xdat.om.XnatProjectdata;
import org.nrg.xdat.security.helpers.Permissions; import org.nrg.xdat.security.helpers.Permissions;
import org.nrg.xft.XFTTable; import org.nrg.xft.XFTTable;
...@@ -29,21 +28,21 @@ import org.restlet.resource.Variant; ...@@ -29,21 +28,21 @@ import org.restlet.resource.Variant;
public class ProjectPipelineListResource extends SecureResource { public class ProjectPipelineListResource extends SecureResource {
XnatProjectdata proj = null; XnatProjectdata proj = null;
String pID = null; String pID = null;
public ProjectPipelineListResource(Context context, Request request, Response response) { public ProjectPipelineListResource(Context context, Request request, Response response) {
super(context, request, response); super(context, request, response);
this.getVariants().add(new Variant(MediaType.APPLICATION_JSON)); this.getVariants().add(new Variant(MediaType.APPLICATION_JSON));
this.getVariants().add(new Variant(MediaType.TEXT_XML)); this.getVariants().add(new Variant(MediaType.TEXT_XML));
pID= (String)getParameter(request,"PROJECT_ID"); pID= (String)getParameter(request,"PROJECT_ID");
if(pID!=null){ if(pID!=null){
proj = XnatProjectdata.getProjectByIDorAlias(pID, user, false); proj = XnatProjectdata.getProjectByIDorAlias(pID, user, false);
} }
} }
@Override @Override
public boolean allowGet() { public boolean allowGet() {
return true; return true;
...@@ -53,7 +52,7 @@ public class ProjectPipelineListResource extends SecureResource { ...@@ -53,7 +52,7 @@ public class ProjectPipelineListResource extends SecureResource {
public boolean allowDelete() { public boolean allowDelete() {
return true; return true;
} }
public void handleDelete() { public void handleDelete() {
//Remove the Pipeline identified by the path for the project and the datatype //Remove the Pipeline identified by the path for the project and the datatype
if (proj != null) { if (proj != null) {
...@@ -63,85 +62,109 @@ public class ProjectPipelineListResource extends SecureResource { ...@@ -63,85 +62,109 @@ public class ProjectPipelineListResource extends SecureResource {
datatype = this.getQueryVariable("datatype"); datatype = this.getQueryVariable("datatype");
if (pathToPipeline != null && datatype != null) { if (pathToPipeline != null && datatype != null) {
pathToPipeline = pathToPipeline.trim(); pathToPipeline = pathToPipeline.trim();
datatype = datatype.trim(); datatype=datatype.trim();
boolean isUserAuthorized = isUserAuthorized();
boolean isUserAuthorized = false;
try {
isUserAuthorized = Permissions.canDelete(user, proj);
} catch (Exception e) {
e.printStackTrace();
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, "Encountered exception " + e.getMessage());
return;
}
if (isUserAuthorized) { if (isUserAuthorized) {
try { try {
ArcProject arcProject = ArcSpecManager.GetFreshInstance().getProjectArc(proj.getId()); ArcProject arcProject = ArcSpecManager.GetFreshInstance().getProjectArc(proj.getId());
boolean success = PipelineRepositoryManager.GetInstance().delete(arcProject, pathToPipeline, datatype, user); boolean success = PipelineRepositoryManager.GetInstance().delete(arcProject, pathToPipeline, datatype, user);
if (!success) { if (!success) {
getLogger().log(getLogger().getLevel(), "Couldnt delete the pipeline " + pathToPipeline + " for the project " + proj.getId()); getLogger().log(getLogger().getLevel(), "Couldnt delete the pipeline " + pathToPipeline + " for the project " + proj.getId());
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, " Couldn't successfully save Project Specification"); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, " Couldnt succesfully save Project Specification" );
return; return;
} else { }else {
ArcSpecManager.Reset(); ArcSpecManager.Reset();
returnDefaultRepresentation(); getResponse().setEntity(getRepresentation(getVariants().get(0)));
Representation selectedRepresentation = getResponse().getEntity();
if (getRequest().getConditions().hasSome()) {
final Status status = getRequest().getConditions()
.getStatus(getRequest().getMethod(),
selectedRepresentation);
if (status != null) {
getResponse().setStatus(status);
getResponse().setEntity(null);
}
}
//Send a 200 OK message back //Send a 200 OK message back
//getResponse().setStatus(Status.SUCCESS_OK,"Pipeline has been removed from project " + _project.getId()); //getResponse().setStatus(Status.SUCCESS_OK,"Pipeline has been removed from project " + _project.getId());
} }
} catch (Exception e) { }catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, "Encountered exception " + e.getMessage()); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, "Encountered exception " + e.getMessage());
} }
} else { }else {
getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, "User unauthorized to remove pipeline from project"); getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, "User unauthroized to remove pipeline from project");
} }
} else {
getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED, "Expecting path and datatype as query parameters");
} }
}else {
getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED, "Expecting path and datatype as query parameters");
} }
} }
@Override
public Representation getRepresentation(Variant variant) {
boolean isUserAuthorized;
private boolean isUserAuthorized() {
boolean isUserAuthorized = false;
try { try {
isUserAuthorized = Permissions.canRead(user, proj); isUserAuthorized = Permissions.canDelete(user,proj);
} catch (Exception e) { }catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, "Encountered exception " + e.getMessage()); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
} }
return isUserAuthorized;
}
@Override
public Representation getRepresentation(Variant variant) {
//Document xmldoc = null;
boolean isUserAuthorized = isUserAuthorized();
ArcProject arcProject = ArcSpecManager.GetFreshInstance().getProjectArc(proj.getId());
String comment = "existing";
if (isUserAuthorized) { if (isUserAuthorized) {
ArcProject arcProject = ArcSpecManager.GetFreshInstance().getProjectArc(proj.getId()); boolean additional=this.isQueryVariableTrue("additional");
boolean additional = this.isQueryVariableTrue("additional");
//Check to see if the Project already has an entry in the ArcSpec. //Check to see if the Project already has an entry in the ArcSpec.
//If yes, then return that entry. If not then construct a new ArcProject element and insert an attribute to say that it's an already existing //If yes, then return that entry. If not then construct a new ArcProject element and insert an attribute to say that it's an already existing
//entry or not //entry or not
try { try {
if (additional) { if (arcProject == null) { // No Project pipelines set in the archive specification
PipePipelinerepository repository = PipelineRepositoryManager.GetInstance(); if (additional) {
arcProject = arcProject == null ? repository.createNewArcProject(proj) : repository.getAdditionalPipelines(proj); arcProject = PipelineRepositoryManager.GetInstance().createNewArcProject(proj);
} else { comment = "new";
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, "No archive spec entry for project " + proj.getId()); }else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, "No archive spec entry for project " + proj.getId());
}
}else {
if (additional) { //Return all the pipelines that are applicable to the project but not selected
arcProject = PipelineRepositoryManager.GetInstance().getAdditionalPipelines(proj);
comment = "additional";
}else {
//XFTItem hack = arcProject.getCurrentDBVersion(true);
//arcProject.setItem(hack);
}
} }
} catch(Exception e) { //xmldoc = arcProject.toXML();
//Comment commentNode = xmldoc.createComment(comment);
//xmldoc.appendChild(commentNode);
}catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
} }
MediaType mt = overrideVariant(variant); MediaType mt = overrideVariant(variant);
if (mt.equals(MediaType.TEXT_XML)) { if (mt.equals(MediaType.TEXT_XML)) {
return representItem(arcProject.getItem(), mt, null, false, true); return representItem(arcProject.getItem(), mt, null,false, true);
} else if (mt.equals(MediaType.APPLICATION_JSON)) { }else if (mt.equals(MediaType.APPLICATION_JSON)) {
XFTTable table = PipelineRepositoryManager.GetInstance().toTable(arcProject); XFTTable table = PipelineRepositoryManager.GetInstance().toTable(arcProject);
return representTable(table, mt,null); return representTable(table, mt,null);
} else { }else {
return null; return null;
} }
} else { }else {
getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN); getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN);
} }
return null; return null;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment