@@ -11,9 +11,19 @@ |
*/ |
package m.wepsmetadata; |
|
+import archives.FileArchive; |
+import archives.MongoArchive; |
+import archives.ServiceArchive; |
+import csip.Config; |
import csip.ModelDataService; |
+import csip.PayloadParameter; |
+import csip.PayloadResults; |
import csip.ServiceException; |
+import java.util.ArrayList; |
+import java.util.logging.Level; |
import javax.ws.rs.Path; |
+import models.ModelArchive; |
+import models.WEPSModelArchive; |
import oms3.annotations.Description; |
import oms3.annotations.Name; |
|
@@ -24,20 +34,62 @@ |
@Name("WEPSMetaData") |
@Description("Extracts Metadata from WEPS model runs into sets of meta-model parameters") |
@Path("m/wepsmetadata/1.0") |
-public class V1_0 extends ModelDataService{ |
- |
+public class V1_0 extends ModelDataService { |
+ |
+ protected static String dbLocation = Config.getString("weps.metadata.mongodb", "mongodb://csip.engr.colostate.edu:8095/8084_ftm_csip-weps"); |
+ protected static String serviceName = Config.getString("weps.metadata.service", "http://csip.engr.colostate.edu:8084/csip-weps/m/weps/5.0"); |
+ protected String suid = ""; |
+ protected ServiceArchive mongoArchive; |
+ protected ModelArchive model; |
+ |
@Override |
- public void preProcess() throws ServiceException{ |
+ public void preProcess() throws Exception { |
+ PayloadParameter params = this.parameter(); |
+ ArrayList<ModelArchive> results = null; |
+ |
+ if (params.has("suid")) { |
+ suid = params.getString("suid"); |
+ } else { |
+ throw new ServiceException("Service requires an input suid value"); |
+ } |
+ |
+ if (dbLocation.contains("mongodb://")) { |
+ mongoArchive = new MongoArchive(dbLocation); |
+ } else { |
+ mongoArchive = new FileArchive(dbLocation); |
+ } |
+ |
+ ArrayList<ModelArchive> tArchive = mongoArchive.getArchivesByFilter("_id", suid, 1); |
+ |
+ if (tArchive.isEmpty()) { |
+ throw new ServiceException("Could not find a WEPS model in the archive for that suid and mongodb location."); |
+ } |
+ |
+ model = tArchive.get(0); |
|
+ if (!model.getService().equalsIgnoreCase(serviceName)) { |
+ throw new ServiceException("Could not find a WEPS model in the archive for that suid and mongodb location: Found another type of model for that suid with the service of: " + model.getService()); |
+ } |
+ |
+ if (((WEPSModelArchive)model).badModelRun()) { |
+ throw new ServiceException("Found a WEPS model in the archive, however the model was invalid: " + ((WEPSModelArchive)model).badModelMessage()); |
+ } |
} |
- |
+ |
@Override |
- public void doProcess() throws ServiceException{ |
- |
+ public void doProcess() throws ServiceException { |
+ ((WEPSModelArchive)model).calcWEPSMetaData(); |
+ |
+ try { |
+ mongoArchive.shutdown(); |
+ } catch (Exception ex) { |
+ LOG.log(Level.SEVERE, "Could not shutdown mongo archive at: " + dbLocation, ex); |
+ } |
} |
- |
+ |
@Override |
- public void postProcess() throws Exception{ |
- |
+ public void postProcess() throws Exception { |
+ PayloadResults results = results(); |
+ results.put("meta_model_data", ((WEPSModelArchive)model).getWEPSMetaData().toJSON()); |
} |
} |