Skip to content

Commit

Permalink
support for configuration in /provapi/configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc Moreau committed Sep 28, 2023
1 parent 995645b commit 5dab181
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 27 deletions.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ See also GitHub releases https://github.com/lucmoreau/ProvToolbox/releases
* provx (de)serialization namespace issue
* refining test suite
* default namespace support and testing
* refactoring of InteropFramework with
* readDocument methods
* writeDocument methods
* further refactoring
* provapi configuration information /provapi/configuration


`2.0.2`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ public interface ApiUriFragments {

String FRAGMENT_PROVAPI = "/provapi";
String FRAGMENT_RESOURCES = "/resources/";

String FRAGMENT_CONFIGURATION = "/configuration";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openprovenance.prov.service.core;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.headers.Header;
Expand Down Expand Up @@ -82,6 +83,17 @@ public void addOtherPerformer(Optional<OtherActionPerformer> newOtherPerformer)
otherPerformer = newOtherPerformer;
}

public Map<String, Object> addToConfiguration(String property, Object value) {
this.configuration.put(property, value);
return this.configuration;
}

public Map<String, Object> getConfiguration() {
return configuration;
}

private final Map<String,Object> configuration=new HashMap<>();


@POST
@Path(FRAGMENT_DOCUMENTS_FORM)
Expand Down Expand Up @@ -182,20 +194,27 @@ public Response submit(@Parameter(name = "form",
@POST
@Path(FRAGMENT_DOCUMENTS)
@Tag(name = DOCUMENTS)
@Consumes({MEDIA_TEXT_TURTLE, MEDIA_TEXT_PROVENANCE_NOTATION,
@Consumes({
MEDIA_TEXT_TURTLE, MEDIA_TEXT_PROVENANCE_NOTATION,
MEDIA_APPLICATION_PROVENANCE_XML, MEDIA_APPLICATION_JSON})
@Operation(summary = "Post a document, directly, creates a resource, supports content negotiation, redirects to URL providing serialization for the resource",
@Operation(
summary = "Post a document, directly, creates a resource, supports content negotiation, redirects to URL providing serialization for the resource",
description = "It supports the direct posting of documents using a prov serialization.",
responses = {@ApiResponse(responseCode = "200",
//headers=@Header(name="location",description="Location of posted document"),
content = {@Content(mediaType = MEDIA_TEXT_TURTLE),
@Content(mediaType = MEDIA_TEXT_PROVENANCE_NOTATION),
@Content(mediaType = MEDIA_APPLICATION_PROVENANCE_XML),
@Content(mediaType = MEDIA_APPLICATION_JSON)}),
@ApiResponse(responseCode = "303",
responses = {
@ApiResponse(
responseCode = "200",
//headers=@Header(name="location",description="Location of posted document"),
content = {
@Content(mediaType = MEDIA_TEXT_TURTLE),
@Content(mediaType = MEDIA_TEXT_PROVENANCE_NOTATION),
@Content(mediaType = MEDIA_APPLICATION_PROVENANCE_XML),
@Content(mediaType = MEDIA_APPLICATION_JSON)}),
@ApiResponse(
responseCode = "303",
headers = @Header(name = "location", description = "Location of posted document"),
description = "See other url for serialization of posted resource as requested by accept header."),
@ApiResponse(responseCode = "404", description = "Provenance not found")})
@ApiResponse(
responseCode = "404", description = "Provenance not found")})
public Response submit2(@Parameter(name = "input",
description = "input file in a prov serialization",
example = "document\n prefix ex <http://foo>\n entity(ex:e)\nendDocument") InputStream input,
Expand Down Expand Up @@ -225,6 +244,24 @@ public Response submit2(@Parameter(name = "input",
return utils.composeResponseSeeOther("documents/" + vr.getVisibleId()).header("Expires", date).build();
}

@GET
@Path(FRAGMENT_CONFIGURATION)
@Tag(name = "configuration")
@Operation(
summary = "Get configuration",
description = "Get configuration",
responses = {
@ApiResponse(
responseCode = "200",
content = {
@Content(mediaType = MEDIA_APPLICATION_JSON)})})
public Response getConfiguration(@Context HttpHeaders headers) {
StreamingOutput promise= out -> new ObjectMapper().writeValue(out, configuration);

return ServiceUtils.composeResponseOK(promise).type(InteropMediaType.MEDIA_APPLICATION_JSON).build();
}



private DocumentResource processFileInForm(Map<String, List<InputPart>> formData) {
DocumentResource vr = null;
Expand Down Expand Up @@ -261,7 +298,7 @@ private void doLog(ServiceUtils.Action action, DocumentResource vr) {

private void doLog(String action, DocumentResource vr) {
logger.log(ProvLevel.PROV,
"" + action + ","
action + ","
+ vr.getVisibleId() + ","
+ vr.getStorageId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import static org.openprovenance.prov.service.core.ServiceUtils.UPLOADED_FILE_PATH;

public class ServiceUtilsConfig extends StorageConfig {
public ServiceUtilsConfig() {
public final Map<String, String> configuration;

public ServiceUtilsConfig(Map<String, String> configuration) {
extensionMap = new HashMap<>();
nonDocumentResourceIndex=new NonDocumentResourceIndexInMemory( 100);
nonDocumentResourceStorage=new NonDocumentResourceStorageFileSystem(new File(UPLOADED_FILE_PATH));
genericResourceStorageMap=new HashMap<>();
this.configuration=configuration;
}
public ResourceStorage storageManager;
public int documentCacheSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ public Response getBindings(@Context HttpServletResponse response,
@Context UriInfo info) throws IOException {

final MultivaluedMap<String, String> valueMap = info.getQueryParameters();

String bindingsUrl="https://nms.kcl.ac.uk/luc.moreau/dev/bindings/" + name + ".json";

JsonNode bindings_schema = mapper.readTree(new URL(bindingsUrl));

expandBindingsSchema(bindings_schema, valueMap);

return ServiceUtils.composeResponseOK(bindings_schema).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jboss.resteasy.plugins.interceptors.CorsFilter;
import org.openprovenance.prov.configuration.Configuration;
import org.openprovenance.prov.interop.ApiUriFragments;
import org.openprovenance.prov.interop.InteropFramework;
import org.openprovenance.prov.model.ProvFactory;
Expand Down Expand Up @@ -83,12 +84,19 @@ public class ProvapiApplication extends Application implements ApiUriFragments {
public final StorageConfiguration sc = new StorageConfiguration();

public ProvapiApplication() {
InteropFramework intF=new InteropFramework();
final ProvFactory factory = InteropFramework.getDefaultFactory();

ServiceUtilsConfig config= sc.makeConfig(factory);


PostService ps=new PostService(config);

ps.addToConfiguration("storage.config", config.configuration);
ps.addToConfiguration("cli.config", intF.getConfig());
ps.addToConfiguration("version", Configuration.toolboxVersion);
ps.addToConfiguration("long.version", Configuration.longToolboxVersion);


singletons.add(ps);
singletons.add(new TranslationService(ps));
singletons.add(new TemplateService(ps));
Expand All @@ -112,6 +120,8 @@ public ProvapiApplication() {





logger.info("ProvapiApplication constructor ... completion");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ServiceUtilsConfig makeConfig(ProvFactory factory) {


public ServiceUtilsConfig makeConfig(ProvFactory factory, Map<String,String> configuration) {
ServiceUtilsConfig utilsConfig = new ServiceUtilsConfig();
ServiceUtilsConfig utilsConfig = new ServiceUtilsConfig(configuration);
utilsConfig.pFactory=factory;
logger.info("Configuration --- " + configuration);
switch (configuration.get(PSERVICE_INDEX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
<a href="https://github.com/lucmoreau/ProvToolbox">https://github.com/lucmoreau/ProvToolbox</a><br/>
</address>

<div>
When reporting an issue about ProvToolbox <code>provconvert</code>, please provide the information returned by the command
<code>provconvert --version</code>.
</div>

<div>
When reporting an issue about this service, please provide the information returned by <a href="${service.context}/provapi/configuration">/provapi/configuration</a>.
</div>

</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ServiceUtilsConfig makeConfig(ProvFactory factory) {


public ServiceUtilsConfig makeConfig(ProvFactory factory, Map<String,String> configuration) {
ServiceUtilsConfig utilsConfig = new ServiceUtilsConfig();
ServiceUtilsConfig utilsConfig = new ServiceUtilsConfig(configuration);
utilsConfig.pFactory=factory;
logger.info("Configuration --- " + configuration);
switch (configuration.get(PSERVICE_INDEX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Document makeDocument() {
public void doConversions(Document document, String file) {
InteropFramework intF=new InteropFramework();
intF.writeDocument(file, document);
intF.writeDocument(System.out, Formats.ProvFormat.PROVN, document);
intF.writeDocument(System.out, document, Formats.ProvFormat.PROVN);
}

public void closingBanner() {
Expand Down

0 comments on commit 5dab181

Please sign in to comment.