use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class DbDriver method testSuiteInfosGet.
/**
* Insert the method's description here.
* Creation date: (10/16/2004 2:39:49 PM)
* @return cbit.vcell.numericstest.TestSuiteInfoNew[]
*/
public static TestSuiteInfoNew[] testSuiteInfosGet(Connection con, User user) throws SQLException {
if (!user.isTestAccount()) {
throw new PermissionException("User=" + user.getName() + " not allowed TestSuiteInfo");
}
String sql = "SELECT * FROM " + TFTestSuiteTable.table.getTableName();
Vector<TestSuiteInfoNew> tsiV = new Vector<TestSuiteInfoNew>();
Statement stmt = null;
try {
stmt = con.createStatement();
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal tsKey = rset.getBigDecimal(TFTestSuiteTable.table.id.getUnqualifiedColName());
String tsID = rset.getString(TFTestSuiteTable.table.tsVersion.getUnqualifiedColName());
String vcBuildS = rset.getString(TFTestSuiteTable.table.vcBuildVersion.getUnqualifiedColName());
String vcNumericS = rset.getString(TFTestSuiteTable.table.vcNumericsVersion.getUnqualifiedColName());
java.util.Date date = VersionTable.getDate(rset, TFTestSuiteTable.table.creationDate.getUnqualifiedColName());
String tsAnnot = rset.getString(TFTestSuiteTable.table.tsAnnotation.getUnqualifiedColName());
boolean islocked = rset.getBoolean(TFTestSuiteTable.table.isLocked.getUnqualifiedColName());
tsiV.add(new TestSuiteInfoNew(tsKey, tsID, vcBuildS, vcNumericS, date, tsAnnot, islocked));
}
} finally {
if (stmt != null) {
stmt.close();
}
}
if (tsiV.size() > 0) {
TestSuiteInfoNew[] temp = new TestSuiteInfoNew[tsiV.size()];
tsiV.copyInto(temp);
return temp;
}
return null;
}
use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class DbDriver method curate.
/**
* Insert the method's description here.
* Creation date: (5/23/2006 10:44:52 AM)
*/
public static VCDocumentInfo curate(CurateSpec curateSpec, Connection con, User user, DatabaseSyntax dbSyntax) throws DataAccessException, SQLException {
VersionableType vType = null;
if (curateSpec.getVCDocumentInfo() instanceof BioModelInfo) {
vType = VersionableType.BioModelMetaData;
} else if (curateSpec.getVCDocumentInfo() instanceof MathModelInfo) {
vType = VersionableType.MathModelMetaData;
} else {
throw new DataAccessException("Expecting BioModelInfo or MathModelInfo but got type=" + curateSpec.getVCDocumentInfo().getClass().getName());
}
KeyValue vKey = curateSpec.getVCDocumentInfo().getVersion().getVersionKey();
Version dbVersion = getVersionFromKeyValue(con, vType, vKey);
// Must be owner to curate
if (!dbVersion.getOwner().compareEqual(user)) {
throw new PermissionException("Cannot curate " + vType.getTypeName() + " \"" + dbVersion.getName() + "\" (" + vKey + "), not owned by " + user.getName());
}
VersionFlag updatedVersionFlag = null;
if (curateSpec.getCurateType() == CurateSpec.ARCHIVE) {
if (!dbVersion.getFlag().compareEqual(VersionFlag.Current)) {
throw new IllegalArgumentException("Only non-archived, non-published documents can be ARCHIVED");
}
updatedVersionFlag = VersionFlag.Archived;
} else if (curateSpec.getCurateType() == CurateSpec.PUBLISH) {
// Must have PUBLISH rights
if (!dbVersion.getOwner().isPublisher()) {
throw new PermissionException("Cannot curate " + vType.getTypeName() + " \"" + dbVersion.getName() + "\" (" + vKey + "), user " + user.getName() + " not granted PUBLISHING rights");
}
// Must be ARCHIVED and Public before PUBLISH is allowed
if (!dbVersion.getFlag().compareEqual(VersionFlag.Archived) || !(dbVersion.getGroupAccess() instanceof GroupAccessAll)) {
throw new IllegalArgumentException("Only ARCHIVED documents with PUBLIC permission can be PUBLISHED");
}
updatedVersionFlag = VersionFlag.Published;
} else {
throw new DataAccessException("Expecting CurateType " + CurateSpec.ARCHIVE + "(ARCHIVE) or " + CurateSpec.PUBLISH + "(PUBLISH) but got type=" + curateSpec.getCurateType());
}
VersionTable vTable = VersionTable.getVersionTable(vType);
String set = vTable.versionFlag.getQualifiedColName() + " = " + updatedVersionFlag.getIntValue();
String cond = vTable.id.getQualifiedColName() + " = " + vKey;
String sql = DatabasePolicySQL.enforceOwnershipUpdate(user, vTable, set, cond);
int numRowsProcessed = updateCleanSQL(con, sql);
// Clear XML
if (vType.equals(VersionableType.BioModelMetaData)) {
updateCleanSQL(con, "DELETE FROM " + BioModelXMLTable.table.getTableName() + " WHERE " + BioModelXMLTable.table.bioModelRef.getQualifiedColName() + " = " + vKey.toString());
} else if (vType.equals(VersionableType.MathModelMetaData)) {
updateCleanSQL(con, "DELETE FROM " + MathModelXMLTable.table.getTableName() + " WHERE " + MathModelXMLTable.table.mathModelRef.getQualifiedColName() + " = " + vKey.toString());
}
VCDocumentInfo dbVCDocumentInfo = (VCDocumentInfo) getVersionableInfos(con, user, vType, false, vKey, false, dbSyntax).elementAt(0);
return dbVCDocumentInfo;
}
use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class OptimizationServerResource method getOptRun.
private OptRun getOptRun(User vcellUser) {
// }else{
try {
String optimizationId = (String) getRequestAttributes().get(VCellApiApplication.OPTIMIZATIONID);
VCellApiApplication application = ((VCellApiApplication) getApplication());
OptRunContext optRunContext = application.getOptServerImpl().getOptRunContextByOptimizationId(optimizationId);
if (optRunContext == null) {
throw new ObjectNotFoundException("optimization id '" + optimizationId + "' not found");
}
switch(optRunContext.getStatus()) {
case Complete:
{
OptRun optRun = CopasiServicePython.readOptRun(optRunContext.getOptRunBinaryFile());
return optRun;
}
case Queued:
case Running:
case Failed:
{
OptProblem optProblem = CopasiServicePython.readOptProblem(optRunContext.getOptProblemBinaryFile());
OptRun optRun = new OptRun();
optRun.setOptProblem(optProblem);
optRun.setStatus(optRunContext.getStatus());
optRun.setStatusMessage(optRunContext.getStatus().name());
return optRun;
}
default:
{
throw new RuntimeException("unexpected optimization status '" + optRunContext.getStatus() + "'");
}
}
} 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, "optimization not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of org.vcell.util.PermissionException 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 org.vcell.util.PermissionException 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