use of cbit.vcell.modeldb.BioModelReferenceRep in project vcell by virtualcell.
the class PublicationServerResource method handleForm.
@Post
public Representation handleForm(Representation entity) {
try {
String myHost = getHostRef().getHostDomain();
String allowedPublicationHost = PropertyLoader.getProperty(PropertyLoader.vcellPublicationHost, "");
if (!allowedPublicationHost.equals(myHost)) {
throw new PermissionException("Host '" + myHost + "' not allowed to edit publications");
}
Form form = new Form(entity);
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
if (vcellUser == null) {
throw new PermissionException("must be authenticated to edit publication info");
}
// The form contains input with names "user" and "password"
String pubop = form.getFirstValue("pubop");
// String password = form.getFirstValue("password");
Map<String, Object> dataModel = new HashMap<String, Object>();
if (pubop == null) {
return new StringRepresentation(("value of publication 'operation' cannot be null"));
} else if (pubop.equals("editNew")) {
PublicationRepresentation value = new PublicationRepresentation();
value.pubKey = AUTOMATICALLY_GENERATED;
dataModel.put("publicationRepr", value);
} else if (pubop.equals("editWithKey")) {
Object pubidObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
PublicationRepresentation publication = getPublicationRepresentation(((VCellApiApplication) getApplication()).getRestDatabaseService(), vcellUser, new KeyValue(pubidObj.toString()));
dataModel.put("publicationRepr", publication);
} else if (pubop.equals("applyEdit")) {
SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy", java.util.Locale.US);
// PublicationRepresentation publication = getPublicationRepresentation(((VCellApiApplication)getApplication()).getRestDatabaseService(),vcellUser,new KeyValue(form.getFirstValue("pubid")));
String[] authors = StringUtils.split(form.getFirstValue("authors"), ";");
for (int i = 0; i < authors.length; i++) {
authors[i] = authors[i].trim();
}
String thePubID = form.getFirstValue("pubId");
BioModelReferenceRep[] bioModelReferenceReps = (BioModelReferenceRep[]) convertToReferenceRep(form.getFirstValue("biomodelReferences"), BioModelReferenceRep.class);
MathModelReferenceRep[] mathModelReferenceReps = (MathModelReferenceRep[]) convertToReferenceRep(form.getFirstValue("mathmodelReferences"), MathModelReferenceRep.class);
PublicationRep publicationRep = new PublicationRep((thePubID == null || thePubID.equals(AUTOMATICALLY_GENERATED) ? null : new KeyValue(Integer.valueOf(thePubID).toString())), form.getFirstValue("title"), authors, (form.getFirstValue("year") == null || form.getFirstValue("year").trim().length() == 0 ? null : Integer.valueOf(form.getFirstValue("year"))), form.getFirstValue("citation"), form.getFirstValue("pubmedid"), form.getFirstValue("doi"), form.getFirstValue("endnoteid"), form.getFirstValue("url"), bioModelReferenceReps, mathModelReferenceReps, form.getFirstValue("wittid"), (form.getFirstValue("pubdate") == null || form.getFirstValue("pubdate").trim().length() == 0 ? null : sdf.parse(form.getFirstValue("pubdate"))));
KeyValue savedOrEditedPubID = ((VCellApiApplication) getApplication()).getRestDatabaseService().savePublicationRep(publicationRep, vcellUser);
// String address = getRequest().getClientInfo().getAddress();
// int port = getRequest().getClientInfo().getPort();
StringRepresentation s = getPubInfoHtml(myHost, savedOrEditedPubID);
return s;
} else if (pubop.equals("makepublic")) {
String[] bmKeys = form.getValuesArray("bmpublic");
KeyValue[] publishTheseBiomodels = new KeyValue[(bmKeys == null ? 0 : bmKeys.length)];
for (int i = 0; i < publishTheseBiomodels.length; i++) {
publishTheseBiomodels[i] = new KeyValue(bmKeys[i]);
}
String[] mmKeys = form.getValuesArray("mmpublic");
KeyValue[] publishTheseMathmodels = new KeyValue[(mmKeys == null ? 0 : mmKeys.length)];
for (int i = 0; i < publishTheseMathmodels.length; i++) {
publishTheseMathmodels[i] = new KeyValue(mmKeys[i]);
}
if (publishTheseBiomodels.length > 0 || publishTheseMathmodels.length > 0) {
((VCellApiApplication) getApplication()).getRestDatabaseService().publishDirectly(publishTheseBiomodels, publishTheseMathmodels, vcellUser);
}
Object pubidObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
StringRepresentation s = getPubInfoHtml(myHost, new KeyValue(pubidObj.toString()));
return s;
} else {
return new StringRepresentation(("value of pubop=" + pubop + " not expected").toCharArray());
}
Configuration templateConfiguration = application.getTemplateConfiguration();
Representation myRepresentation = new ClientResource(LocalReference.createClapReference("/newpublication.ftl")).get();
TemplateRepresentation templateRepresentation = new TemplateRepresentation(myRepresentation, templateConfiguration, dataModel, MediaType.TEXT_HTML);
return templateRepresentation;
} catch (Exception e) {
return new StringRepresentation(e.getClass().getName() + " " + e.getMessage());
}
}
Aggregations