Skip to content

Commit

Permalink
solves #17
Browse files Browse the repository at this point in the history
DUI for elements includes a dropdown meny of all supported resource
types.
  • Loading branch information
jadelkhoury committed Oct 4, 2020
1 parent 4e8d05e commit 53341ae
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.eclipse.lyo.oslc4j.core.model.ServiceProvider;
import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
import org.eclipse.lyo.oslc4j.core.model.IResource;
import org.oasis.oslcop.sysml.servlet.ServiceProviderCatalogSingleton;
import org.oasis.oslcop.sysml.ServiceProviderInfo;
import org.oasis.oslcop.sysml.SysmlClass;
Expand Down Expand Up @@ -283,10 +284,13 @@ public static List<Element> ElementSelector(HttpServletRequest httpServletReques
List<Element> resources = null;

// Start of user code ElementSelector_storeInit
String selectType = httpServletRequest.getParameter("selectType");
String prefix = "rdf=" + "<" + org.apache.jena.vocabulary.RDF.uri + ">";
String where = "rdf:type=" + "<" + SysmlDomainConstants.SYSML_NAMSPACE + selectType + ">";
// End of user code
Store store = storePool.getStore();
try {
resources = new ArrayList<Element>(store.getResources(storePool.getDefaultNamedGraphUri(), Element.class, "", "", terms, 20, -1));
resources = new ArrayList<Element>(store.getResources(storePool.getDefaultNamedGraphUri(), Element.class, prefix, where, terms, 20, -1));
} catch (StoreAccessException | ModelUnmarshallingException e) {
log.error("Failed to search resources, with search-term '" + terms + "'", e);
throw new WebApplicationException("Failed to search resources, with search-term '" + terms + "'", e, Status.INTERNAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
import io.swagger.annotations.ApiOperation;

// Start of user code imports
import java.io.FileInputStream;
import java.util.Properties;
// End of user code

// Start of user code pre_class_code
Expand All @@ -112,9 +114,25 @@ public class ServiceProviderService2
private static final Logger log = LoggerFactory.getLogger(ServiceProviderService2.class);

// Start of user code class_attributes
private static List<String> servicedResources = null;
// End of user code

// Start of user code class_methods
public static List<String> getServicedResources() {
if (null == servicedResources) {
Properties servicedResourcesProperties = new Properties();
String servicedResourcesPropertiesFile = ServiceProviderService2.class.getResource("/servicedResources.properties").getFile();
try {
servicedResourcesProperties.load(new FileInputStream(servicedResourcesPropertiesFile));
} catch (IOException e) {
log.error("Failed to open the 'servicedResources' properties file.", e);
throw new RuntimeException(e);
}
servicedResources = Arrays.asList(servicedResourcesProperties.getProperty("servicedResources").split(";"));
}
return servicedResources;
}

// End of user code

public ServiceProviderService2()
Expand Down Expand Up @@ -248,6 +266,7 @@ public void ElementSelector(
) throws ServletException, IOException
{
// Start of user code ElementSelector_init
httpServletRequest.setAttribute("servicedResources", getServicedResources());
// End of user code

httpServletRequest.setAttribute("selectionUri",UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path(uriInfo.getPath()).build().toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
servicedResources=Class;Subsetting;Relationship;Generalization
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
<%@page import="org.oasis.oslcop.sysml.Element"%>
<%@page import="org.eclipse.lyo.oslc4j.core.OSLC4JUtils"%>
<%@page import="javax.ws.rs.core.UriBuilder"%>
<%@page import="java.util.List"%>

<%@ page contentType="text/html" language="java" pageEncoding="UTF-8" %>

<%
String selectionUri = (String) request.getAttribute("selectionUri");
List<String> servicedResources = (List<String>) request.getAttribute("servicedResources");
%>

<html>
Expand All @@ -43,6 +44,11 @@
</head>
<body style="padding: 10px;">
<div id="selector-body">
Type: <select id="selectType">
<%for (String r : servicedResources) {%>
<option value="<%=r%>"><%=r%></option>
<%}%>
</select>
<p id="searchMessage">Find a specific resource through a free-text search.</p>

<p id="loadingMessage" style="display: none;">Pondering your search. Please stand by ...</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function search(baseUrl){
}
};
terms = document.getElementById("searchTerms").value;
xmlhttp.open("GET", baseUrl + "?terms=" + encodeURIComponent(terms), true);
selectType = document.getElementById("selectType").value;
xmlhttp.open("GET", baseUrl + "?terms=" + encodeURIComponent(terms) + "&selectType=" + selectType, true);
searchMessage.style.display = 'none';
loadingMessage.style.display = 'block';
xmlhttp.send();
Expand Down

0 comments on commit 53341ae

Please sign in to comment.