Skip to content

Commit 723709b

Browse files
Merge pull request #23 from NCEAS/develop
3.0.0 Release
2 parents ab36599 + b89689b commit 723709b

File tree

9 files changed

+1780
-181
lines changed

9 files changed

+1780
-181
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
docker-publish:
4848
name: Docker Build and Publish
49-
if: github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/v')
49+
if: github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref_name, 'feature')
5050
needs: maven-build
5151
runs-on: ubuntu-latest
5252
permissions:

.vscode/eclipse-java-google-style.xml

Lines changed: 337 additions & 0 deletions
Large diffs are not rendered by default.

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive",
3+
"java.compile.nullAnalysis.mode": "automatic",
4+
"java.format.settings.url": ".vscode/eclipse-java-google-style.xml"
5+
}

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
77
<!-- <docker.registry>docker.io</docker.registry> -->
88
<docker.repo>metadig</docker.repo>
9-
<docker.tag>2.5.0</docker.tag>
10-
<metadig-engine-version>2.5.0</metadig-engine-version>
9+
<docker.tag>3.0.0</docker.tag>
10+
<metadig-engine-version>3.0.0</metadig-engine-version>
1111
</properties>
1212

1313
<modelVersion>4.0.0</modelVersion>
1414

1515
<groupId>edu.ucsb.nceas</groupId>
1616
<artifactId>metadig-webapp</artifactId>
1717
<packaging>war</packaging>
18-
<version>2.5.0</version>
18+
<version>3.0.0-SNAPSHOT</version>
1919
<name>metadig-webapp</name>
2020

2121
<repositories>

src/main/java/edu/ucsb/nceas/mdq/MetadigContextListener.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
import javax.servlet.ServletContextListener;
88
import java.io.IOException;
99
import java.util.concurrent.TimeoutException;
10+
import edu.ucsb.nceas.mdqengine.dispatch.Dispatcher;
1011
import edu.ucsb.nceas.mdqengine.Controller;
12+
import edu.ucsb.nceas.mdqengine.exception.MetadigException;
1113

14+
@WebListener
1215
public class MetadigContextListener implements ServletContextListener {
1316

1417
public static Log log = LogFactory.getLog(MetadigContextListener.class);
1518

1619
@Override
1720
public void contextInitialized(ServletContextEvent servletContextEvent) {
18-
log.debug("Metadig 'contextInitialized' called.");
21+
try {
22+
Dispatcher.setupJep();
23+
} catch (MetadigException e) {
24+
throw new RuntimeException("Error setting up Jep. Aborting startup.", e);
25+
}
26+
27+
log.info("Metadig 'contextInitialized' called.");
1928
}
2029

2130
@Override
@@ -26,7 +35,7 @@ public void contextDestroyed(ServletContextEvent servletContextEvent) {
2635
try {
2736
log.debug("Shutting down controller...");
2837
controller.shutdown();
29-
log.info("Controller shutdonw successfully.");
38+
log.info("Controller shut down successfully.");
3039
} catch (IOException | TimeoutException e) {
3140
log.error("Error shutting down metadig controller.");
3241
e.printStackTrace();

src/main/java/edu/ucsb/nceas/mdq/rest/ChecksResource.java

Lines changed: 85 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
import javax.ws.rs.Produces;
1919
import javax.ws.rs.core.Context;
2020
import javax.ws.rs.core.MediaType;
21-
import javax.ws.rs.core.MultivaluedMap;
2221
import javax.ws.rs.core.Request;
2322
import javax.ws.rs.core.Response;
2423
import javax.ws.rs.core.Variant;
2524
import javax.xml.bind.JAXBException;
2625

27-
import com.hp.hpl.jena.shared.ConfigException;
2826
import edu.ucsb.nceas.mdqengine.exception.MetadigException;
2927
import edu.ucsb.nceas.mdqengine.exception.MetadigStoreException;
30-
import net.sf.saxon.functions.ConstantFunction;
3128
import org.apache.commons.configuration2.ex.ConfigurationException;
3229
import org.apache.commons.io.IOUtils;
3330
import org.apache.commons.logging.Log;
@@ -44,31 +41,32 @@
4441
import edu.ucsb.nceas.mdqengine.store.StoreFactory;
4542
import edu.ucsb.nceas.mdqengine.serialize.JsonMarshaller;
4643
import edu.ucsb.nceas.mdqengine.serialize.XmlMarshaller;
44+
import edu.ucsb.nceas.mdqengine.dispatch.Dispatcher;
4745

4846
/**
4947
* Root resource (exposed at "checks" path)
5048
*/
5149
@Path("checks")
5250
public class ChecksResource {
53-
54-
private Log log = LogFactory.getLog(this.getClass());
55-
56-
private MDQStore store = null;
57-
58-
private MDQEngine engine = null;
59-
60-
public ChecksResource() throws MetadigStoreException {
61-
boolean persist = false;
62-
this.store = StoreFactory.getStore(persist);
51+
52+
private Log log = LogFactory.getLog(this.getClass());
53+
54+
private MDQStore store = null;
55+
56+
private MDQEngine engine = null;
57+
58+
public ChecksResource() throws MetadigStoreException {
59+
boolean persist = false;
60+
this.store = StoreFactory.getStore(persist);
6361

64-
try {
65-
this.engine = new MDQEngine();
66-
this.engine.setStore(this.store);
67-
} catch (MetadigException | IOException | ConfigurationException e) {
68-
log.error(e.getMessage(), e);
69-
}
70-
}
71-
62+
try {
63+
this.engine = new MDQEngine();
64+
this.engine.setStore(this.store);
65+
} catch (MetadigException | IOException | ConfigurationException e) {
66+
log.error(e.getMessage(), e);
67+
}
68+
}
69+
7270
/**
7371
* Method handling HTTP GET requests. The returned object will be sent
7472
* to the client as "text/plain" media type.
@@ -78,53 +76,56 @@ public ChecksResource() throws MetadigStoreException {
7876
@GET
7977
@Produces(MediaType.APPLICATION_JSON)
8078
public String listChecks() {
81-
Collection<String> checks = store.listChecks();
79+
Collection<String> checks = store.listChecks();
8280
return JsonMarshaller.toJson(checks);
8381
}
8482

8583
@GET
8684
@Path("/{id}")
8785
@Produces(MediaType.TEXT_XML)
8886
public String getCheck(@PathParam("id") String id) throws UnsupportedEncodingException, JAXBException {
89-
Check check = store.getCheck(id);
87+
Check check = store.getCheck(id);
9088
return (String) XmlMarshaller.toXml(check, true);
9189
}
9290

9391
// @POST
9492
// @Consumes(MediaType.MULTIPART_FORM_DATA)
93+
// not enabled for security reasons, see: https://github.com/NCEAS/metadig-webapp/issues/21
9594
public boolean createCheck(@FormDataParam("check") InputStream xml) {
96-
Check check = null;
97-
try {
98-
check = (Check) XmlMarshaller.fromXml(IOUtils.toString(xml, "UTF-8"), Check.class);
99-
store.createCheck(check);
100-
} catch (Exception e) {
101-
log.error(e.getMessage(), e);
102-
return false;
103-
}
95+
Check check = null;
96+
try {
97+
check = (Check) XmlMarshaller.fromXml(IOUtils.toString(xml, "UTF-8"), Check.class);
98+
store.createCheck(check);
99+
} catch (Exception e) {
100+
log.error(e.getMessage(), e);
101+
return false;
102+
}
104103
return true;
105104
}
106105

107106
// @PUT
108107
// @Path("/{id}")
109108
// @Consumes(MediaType.MULTIPART_FORM_DATA)
109+
// not enabled for security reasons, see: https://github.com/NCEAS/metadig-webapp/issues/21
110110
public boolean updateCheck(@PathParam("id") String id, @FormDataParam("check") InputStream xml) throws JAXBException, IOException {
111-
Check check = null;
112-
try {
113-
check = (Check) XmlMarshaller.fromXml(IOUtils.toString(xml, "UTF-8"), Check.class);
114-
store.updateCheck(check);
115-
} catch (Exception e) {
116-
log.error(e.getMessage(), e);
117-
return false;
118-
}
111+
Check check = null;
112+
try {
113+
check = (Check) XmlMarshaller.fromXml(IOUtils.toString(xml, "UTF-8"), Check.class);
114+
store.updateCheck(check);
115+
} catch (Exception e) {
116+
log.error(e.getMessage(), e);
117+
return false;
118+
}
119119
return true;
120120
}
121121

122122
// @DELETE
123123
// @Path("/{id}")
124124
// @Produces(MediaType.TEXT_PLAIN)
125+
// not enabled for security reasons, see: https://github.com/NCEAS/metadig-webapp/issues/21
125126
public boolean updateCheck(@PathParam("id") String id) {
126-
Check check = store.getCheck(id);
127-
store.deleteCheck(check);
127+
Check check = store.getCheck(id);
128+
store.deleteCheck(check);
128129
return true;
129130
}
130131

@@ -133,51 +134,49 @@ public boolean updateCheck(@PathParam("id") String id) {
133134
@Consumes(MediaType.MULTIPART_FORM_DATA)
134135
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
135136
public Response run(
136-
@PathParam("id") String id,
137-
@FormDataParam("document") InputStream input,
138-
@FormDataParam("systemMetadata") InputStream sysMetaStream,
139-
@Context Request r) throws UnsupportedEncodingException, JAXBException {
140-
141-
Run run = null;
142-
// include SM if it was provided
143-
SystemMetadata sysMeta = null;
144-
if (sysMetaStream != null) {
145-
try {
146-
sysMeta = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysMetaStream);
147-
} catch (InstantiationException | IllegalAccessException
148-
| IOException | MarshallingException e) {
149-
log.warn("Could not unmarshall SystemMetadata from stream", e);
150-
}
151-
}
152-
try {
153-
Map<String, Object> params = new HashMap<String, Object>();
154-
// params.putAll(formParams);
155-
// params.remove("id");
156-
// params.remove("document");
157-
Check check = store.getCheck(id);
158-
run = engine.runCheck(check, input, params, sysMeta);
159-
store.createRun(run);
160-
} catch (Exception e) {
161-
log.error(e.getMessage(), e);
162-
return Response.serverError().entity(e).build();
163-
}
164-
165-
// determine the format of plot to return
137+
@PathParam("id") String id,
138+
@FormDataParam("document") InputStream input,
139+
@FormDataParam("systemMetadata") InputStream sysMetaStream,
140+
@Context Request r) throws UnsupportedEncodingException, JAXBException {
141+
142+
Run run = null;
143+
// include SM if it was provided
144+
SystemMetadata sysMeta = null;
145+
if (sysMetaStream != null) {
146+
try {
147+
sysMeta = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysMetaStream);
148+
} catch (InstantiationException | IllegalAccessException
149+
| IOException | MarshallingException e) {
150+
log.warn("Could not unmarshall SystemMetadata from stream", e);
151+
}
152+
}
153+
try {
154+
Map<String, Object> params = new HashMap<String, Object>();
155+
Check check = store.getCheck(id);
156+
run = engine.runCheck(check, input, params, sysMeta);
157+
store.createRun(run);
158+
Dispatcher.getDispatcher("python").close();
159+
} catch (Exception e) {
160+
log.error(e.getMessage(), e);
161+
return Response.serverError().entity(e).build();
162+
}
163+
164+
// determine the format of plot to return
166165
String resultString = null;
167-
List<Variant> vs =
168-
Variant.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).build();
169-
Variant v = r.selectVariant(vs);
170-
if (v == null) {
171-
return Response.notAcceptable(vs).build();
172-
} else {
173-
MediaType mt = v.getMediaType();
174-
if (mt.equals(MediaType.APPLICATION_XML_TYPE)) {
175-
resultString = XmlMarshaller.toXml(run, true);
176-
} else {
177-
resultString = JsonMarshaller.toJson(run);
178-
}
179-
}
180-
181-
return Response.ok(resultString).build();
166+
List<Variant> vs =
167+
Variant.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).build();
168+
Variant v = r.selectVariant(vs);
169+
if (v == null) {
170+
return Response.notAcceptable(vs).build();
171+
} else {
172+
MediaType mt = v.getMediaType();
173+
if (mt.equals(MediaType.APPLICATION_XML_TYPE)) {
174+
resultString = XmlMarshaller.toXml(run, true);
175+
} else {
176+
resultString = JsonMarshaller.toJson(run);
177+
}
178+
}
179+
180+
return Response.ok(resultString).build();
182181
}
183182
}

0 commit comments

Comments
 (0)