use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.
the class PublicationServerResource method getPublicationRepresentation.
private static PublicationRepresentation getPublicationRepresentation(RestDatabaseService restDatabaseService, User vcellUser, KeyValue pubID) {
// RestDatabaseService restDatabaseService = ((VCellApiApplication)getApplication()).getRestDatabaseService();
try {
PublicationRep publicationRep = restDatabaseService.getPublicationRep(pubID, vcellUser);
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
return publicationRepresentation;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (ObjectNotFoundException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "publication not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.
the class RestDatabaseService method getPublicationRep.
public PublicationRep getPublicationRep(KeyValue pubKey, User vcellUser) throws SQLException, ObjectNotFoundException, DataAccessException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
ArrayList<String> conditions = new ArrayList<String>();
if (pubKey != null) {
conditions.add("(" + PublicationTable.table.id.getQualifiedColName() + " = " + pubKey.toString() + ")");
} else {
throw new RuntimeException("bioModelID not specified");
}
StringBuffer conditionsBuffer = new StringBuffer();
for (String condition : conditions) {
if (conditionsBuffer.length() > 0) {
conditionsBuffer.append(" AND ");
}
conditionsBuffer.append(condition);
}
PublicationRep[] publicationReps = databaseServerImpl.getPublicationReps(vcellUser, conditionsBuffer.toString(), null);
if (publicationReps == null || publicationReps.length != 1) {
throw new ObjectNotFoundException("failed to get publication");
}
return publicationReps[0];
}
use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.
the class RestDatabaseService method query.
public PublicationRep[] query(PublicationsServerResource resource, User vcellUser) throws SQLException, DataAccessException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
Long pubID = resource.getLongQueryValue(PublicationsServerResource.PARAM_PUB_ID);
// it is ok if the orderBy is null;
String orderByParam = resource.getQueryValue(PublicationsServerResource.PARAM_ORDERBY);
ArrayList<String> conditions = new ArrayList<String>();
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss", java.util.Locale.US);
if (pubID != null) {
conditions.add("(" + PublicationTable.table.id.getQualifiedColName() + " = " + pubID + ")");
}
StringBuffer conditionsBuffer = new StringBuffer();
for (String condition : conditions) {
if (conditionsBuffer.length() > 0) {
conditionsBuffer.append(" AND ");
}
conditionsBuffer.append(condition);
}
// default
OrderBy orderBy = OrderBy.year_desc;
if (orderByParam != null) {
if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_YEAR_ASC)) {
orderBy = OrderBy.year_asc;
} else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_YEAR_DESC)) {
orderBy = OrderBy.year_desc;
} else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_NAME_ASC)) {
orderBy = OrderBy.name_asc;
} else if (orderByParam.equals(BiomodelsServerResource.PARAM_ORDERBY_NAME_DESC)) {
orderBy = OrderBy.name_desc;
}
}
PublicationRep[] publicationReps = databaseServerImpl.getPublicationReps(vcellUser, conditionsBuffer.toString(), orderBy);
return publicationReps;
}
use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.
the class PublicationServerResource method getPublicationRepresentation.
private PublicationRepresentation getPublicationRepresentation(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
PublicationRep publicationRep = restDatabaseService.query(this, vcellUser);
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
return publicationRepresentation;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (ObjectNotFoundException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "publication not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of cbit.vcell.modeldb.PublicationRep in project vcell by virtualcell.
the class PublicationsServerResource method getPublicationRepresentations.
private PublicationRepresentation[] getPublicationRepresentations(User vcellUser) {
ArrayList<PublicationRepresentation> publicationRepresentations = new ArrayList<PublicationRepresentation>();
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
PublicationRep[] publicationReps = restDatabaseService.query(this, vcellUser);
for (PublicationRep publicationRep : publicationReps) {
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
publicationRepresentations.add(publicationRepresentation);
}
} catch (PermissionException ee) {
ee.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized");
} catch (DataAccessException | SQLException | ExpressionException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve biomodels from VCell Database : " + e.getMessage());
}
return publicationRepresentations.toArray(new PublicationRepresentation[0]);
}
Aggregations