Skip to content
Snippets Groups Projects
Commit dc085e42 authored by tpylak's avatar tpylak
Browse files

LMS-1491 screening api: improve exception handling, include HighLevelExceptions in the API

SVN: 15612
parent 13999362
No related branches found
No related tags found
No related merge requests found
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
<property name="variant" value="-screening" /> <property name="variant" value="-screening" />
<property name="dist.screening-api" value="${dist}/screening_api" /> <property name="dist.screening-api" value="${dist}/screening_api" />
<property name="dist.screening-api.lib" value="${dist.screening-api}/lib" /> <property name="dist.screening-api.lib" value="${dist.screening-api}" />
<property name="dist.screening-api.jar" value="${dist.screening-api.lib}/openbis_screening_api.jar" /> <property name="dist.screening-api.jar" value="${dist.screening-api.lib}/openbis_screening_api.jar" />
<property name="dist.screening-api.javadoc" value="${dist.screening-api}/doc" /> <property name="dist.screening-api.javadoc" value="${dist.screening-api}/doc" />
<property name="classes.screening" value="../screening/targets/www/WEB-INF/classes" /> <property name="classes.screening" value="../screening/targets/www/WEB-INF/classes" />
<property name="classes.common-server" value="../server-common/targets/ant/classes" /> <property name="classes.common-server" value="../server-common/targets/ant/classes" />
<property name="classes.common" value="../common/targets/ant/classes" />
<target name="compile" depends="build-common.compile, clean" /> <target name="compile" depends="build-common.compile, clean" />
...@@ -122,6 +123,7 @@ ...@@ -122,6 +123,7 @@
</fileset> </fileset>
<manifest> <manifest>
<attribute name="Main-Class" value="ch.systemsx.cisd.openbis.plugin.screening.client.api.v1.ScreeningClientApiTest" /> <attribute name="Main-Class" value="ch.systemsx.cisd.openbis.plugin.screening.client.api.v1.ScreeningClientApiTest" />
<attribute name="Class-Path" value="spring-ext.jar" />
<attribute name="Version" value="${version.number}" /> <attribute name="Version" value="${version.number}" />
<attribute name="Build-Number" <attribute name="Build-Number"
value="${version.number} (r${revision.number},${clean.flag})" /> value="${version.number} (r${revision.number},${clean.flag})" />
...@@ -129,15 +131,20 @@ ...@@ -129,15 +131,20 @@
</recursive-jar> </recursive-jar>
<jar update="true" destfile="${dist.screening-api.jar}"> <jar update="true" destfile="${dist.screening-api.jar}">
<fileset dir="${classes.common-server}"> <fileset dir="${classes.common-server}">
<include name="ch/systemsx/cisd/common/spring/*.class" /> <include name="ch/systemsx/cisd/common/spring/HttpInvokerUtils.class" />
</fileset> </fileset>
<fileset dir="${classes.common}">
<include name="ch/systemsx/cisd/common/exceptions/**/*.class" />
</fileset>
</jar>
<recursive-jar destfile="${dist.screening-api.lib}/spring-ext.jar">
<zipfileset src="${lib}/spring/spring.jar" /> <zipfileset src="${lib}/spring/spring.jar" />
<zipfileset src="${lib}/spring/third-party/stream-supporting-httpinvoker.jar" /> <zipfileset src="${lib}/spring/third-party/stream-supporting-httpinvoker.jar" />
<zipfileset src="${lib}/commons-logging/commons-logging.jar" /> <zipfileset src="${lib}/commons-logging/commons-logging.jar" />
<zipfileset src="${lib}/commons-httpclient/commons-httpclient.jar" /> <zipfileset src="${lib}/commons-httpclient/commons-httpclient.jar" />
<zipfileset src="${lib}/commons-codec/commons-codec.jar" /> <zipfileset src="${lib}/commons-codec/commons-codec.jar" />
<zipfileset src="${lib}/log4j/log4j.jar" /> <zipfileset src="${lib}/log4j/log4j.jar" />
</jar> </recursive-jar>
</target> </target>
<target name="screening-api" depends="screening-api-doc, screening-api-libs" /> <target name="screening-api" depends="screening-api-doc, screening-api-libs" />
......
...@@ -27,8 +27,10 @@ import java.util.List; ...@@ -27,8 +27,10 @@ import java.util.List;
import org.apache.log4j.lf5.util.StreamUtils; import org.apache.log4j.lf5.util.StreamUtils;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDataset;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.IDatasetIdentifier; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.IDatasetIdentifier;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetMetadata;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetReference;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.Plate; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.Plate;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateImageReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateImageReference;
...@@ -68,11 +70,20 @@ public class ScreeningClientApiTest ...@@ -68,11 +70,20 @@ public class ScreeningClientApiTest
System.out.println("Feature vector datasets: " + featureVectorDatasets); System.out.println("Feature vector datasets: " + featureVectorDatasets);
// test for feature vector dataset // test for feature vector dataset
// String datasetCode = "20091214153212961-474922"; // feature vector // String featureVectorDatasetCode = "20100423170945059-29"; // feature vector
String datasetCode = "20091216162628729-475111"; // image String imageDatasetCode = "20100423163638457-16"; // image
IDatasetIdentifier datasetIdentifier = getDatasetIdentifier(facade, datasetCode); IDatasetIdentifier datasetIdentifier = getDatasetIdentifier(facade, imageDatasetCode);
loadImages(facade, datasetIdentifier); loadImages(facade, datasetIdentifier);
List<String> featureNames = facade.listAvailableFeatureNames(featureVectorDatasets);
System.out.println("Feature names: " + featureNames);
List<FeatureVectorDataset> features =
facade.loadFeatures(featureVectorDatasets, featureNames);
System.out.println("Features: " + features);
List<ImageDatasetMetadata> imageMetadata = facade.listImageMetadata(imageDatasets);
System.out.println("Image metadata: " + imageMetadata);
facade.logout(); facade.logout();
} }
...@@ -87,17 +98,20 @@ public class ScreeningClientApiTest ...@@ -87,17 +98,20 @@ public class ScreeningClientApiTest
private static void loadImages(ScreeningOpenbisServiceFacade facade, private static void loadImages(ScreeningOpenbisServiceFacade facade,
IDatasetIdentifier datasetIdentifier) throws FileNotFoundException, IOException IDatasetIdentifier datasetIdentifier) throws FileNotFoundException, IOException
{ {
for (int channel = 1; channel <= 2; channel++) for (int well = 1; well <= 5; well++)
{ {
for (int tile = 4; tile <= 6; tile++) for (int channel = 1; channel <= 2; channel++)
{ {
List<PlateImageReference> imageRefs = new ArrayList<PlateImageReference>(); for (int tile = 1; tile <= 1; tile++)
imageRefs.add(new PlateImageReference(1, 3, tile, channel, datasetIdentifier)); {
List<PlateSingleImage> images = facade.loadImages(imageRefs); List<PlateImageReference> imageRefs = new ArrayList<PlateImageReference>();
saveImages(images); imageRefs.add(new PlateImageReference(well, well, tile, channel,
datasetIdentifier));
List<PlateSingleImage> images = facade.loadImages(imageRefs);
saveImages(images);
}
} }
} }
} }
private static void saveImages(List<PlateSingleImage> images) throws FileNotFoundException, private static void saveImages(List<PlateSingleImage> images) throws FileNotFoundException,
...@@ -116,7 +130,7 @@ public class ScreeningClientApiTest ...@@ -116,7 +130,7 @@ public class ScreeningClientApiTest
private static String createImageFileName(PlateSingleImage image) private static String createImageFileName(PlateSingleImage image)
{ {
WellPosition well = image.getWellPosition(); WellPosition well = image.getWellPosition();
return "img_r" + well.getWellRow() + "_c" + well.getWellColumn() + "_ch" return "img_row" + well.getWellRow() + "_col" + well.getWellColumn() + "_channel"
+ image.getChannel() + "_t" + image.getTile() + ".png"; + image.getChannel() + "_tile" + image.getTile() + ".png";
} }
} }
...@@ -190,83 +190,40 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl ...@@ -190,83 +190,40 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl
public List<FeatureVectorDatasetReference> listFeatureVectorDatasets(String sessionToken, public List<FeatureVectorDatasetReference> listFeatureVectorDatasets(String sessionToken,
List<? extends PlateIdentifier> plates) List<? extends PlateIdentifier> plates)
{ {
try return createScreeningApiImpl(sessionToken).listFeatureVectorDatasets(plates);
{
return createScreeningApiImpl(sessionToken).listFeatureVectorDatasets(plates);
} catch (UserFailureException e)
{
throw translateException(e);
}
} }
public List<ImageDatasetReference> listImageDatasets(String sessionToken, public List<ImageDatasetReference> listImageDatasets(String sessionToken,
List<? extends PlateIdentifier> plates) List<? extends PlateIdentifier> plates)
{ {
try return createScreeningApiImpl(sessionToken).listImageDatasets(plates);
{
return createScreeningApiImpl(sessionToken).listImageDatasets(plates);
} catch (UserFailureException e)
{
throw translateException(e);
}
} }
public List<Plate> listPlates(String sessionToken) public List<Plate> listPlates(String sessionToken)
{ {
try return createScreeningApiImpl(sessionToken).listPlates();
{
return createScreeningApiImpl(sessionToken).listPlates();
} catch (UserFailureException e)
{
throw translateException(e);
}
} }
public List<IDatasetIdentifier> getDatasetIdentifiers(String sessionToken, public List<IDatasetIdentifier> getDatasetIdentifiers(String sessionToken,
List<String> datasetCodes) List<String> datasetCodes)
{ {
try return createScreeningApiImpl(sessionToken).getDatasetIdentifiers(datasetCodes);
{
return createScreeningApiImpl(sessionToken).getDatasetIdentifiers(datasetCodes);
} catch (UserFailureException e)
{
throw translateException(e);
}
} }
private ScreeningApiImpl createScreeningApiImpl(String sessionToken) private ScreeningApiImpl createScreeningApiImpl(String sessionToken)
{ {
try final Session session = getSession(sessionToken);
{ return new ScreeningApiImpl(session, businessObjectFactory, getDAOFactory());
final Session session = getSession(sessionToken);
return new ScreeningApiImpl(session, businessObjectFactory, getDAOFactory());
} catch (UserFailureException e)
{
throw translateException(e);
}
} }
public void logoutScreening(String sessionToken) public void logoutScreening(String sessionToken)
{ {
try logout(sessionToken);
{
logout(sessionToken);
} catch (UserFailureException e)
{
throw translateException(e);
}
} }
public String tryLoginScreening(String userId, String userPassword) public String tryLoginScreening(String userId, String userPassword)
{ {
SessionContextDTO sessionContext; SessionContextDTO sessionContext = tryToAuthenticate(userId, userPassword);
try
{
sessionContext = tryToAuthenticate(userId, userPassword);
} catch (UserFailureException e)
{
throw translateException(e);
}
if (sessionContext != null) if (sessionContext != null)
{ {
return sessionContext.getSessionToken(); return sessionContext.getSessionToken();
...@@ -275,10 +232,4 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl ...@@ -275,10 +232,4 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl
return null; return null;
} }
} }
private static RuntimeException translateException(UserFailureException e)
{
return new IllegalArgumentException(e.getMessage());
}
} }
...@@ -46,7 +46,8 @@ public interface IScreeningApiServer ...@@ -46,7 +46,8 @@ public interface IScreeningApiServer
* *
*@return sessionToken if authentication suceeded, null otherwise *@return sessionToken if authentication suceeded, null otherwise
*/ */
@Transactional(readOnly = true) @Transactional
// this is not a readOnly transaction - it can create new users
String tryLoginScreening(String userId, String userPassword) throws IllegalArgumentException; String tryLoginScreening(String userId, String userPassword) throws IllegalArgumentException;
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment