Skip to content

Commit

Permalink
config upload and load
Browse files Browse the repository at this point in the history
Signed-off-by: Guido Grune <g.grune@datainmotion.com>
  • Loading branch information
gg-dim committed Oct 1, 2024
1 parent 5bad65c commit ee1bcfc
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 559 deletions.
2 changes: 1 addition & 1 deletion backend/cnf/ext/libraries.maven
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ org.geckoprojects.emf:org.gecko.emf.osgi.bnd.library.workspace:6.2.0
org.geckoprojects.emf:org.gecko.emf.osgi.example.model.basic:6.2.0
org.geckoprojects.emf.utils:org.gecko.emf.util.jakartars.bnd.library.workspace:2.3.0
org.geckoprojects.emf.persistence:org.gecko.emf.repository.bnd.library.workspace:6.2.0-SNAPSHOT
org.eclipse.osgi-technology.rest:org.eclipse.osgitech.rest.bnd.library:1.2.2
org.geckoprojects.search:org.gecko.emf.search.bnd.project.library:1.2.0
org.geckoprojects.search:org.gecko.search.bnd.library:1.4.0
org.geckoprojects.bnd:org.gecko.bnd.osgitest.library:1.4.1
org.geckoprojects.utils:org.gecko.util.bnd.library.workspace:1.0.0
org.geckoprojects.emf.utils:org.gecko.emf.util.qvt.bnd.library.workspace.felix:2.0.0-SNAPSHOT
org.geckoprojects.messaging:org.gecko.adapter.messaging.bnd.library.workspace:1.1.0
org.eclipse.osgi-technology.rest:org.eclipse.osgitech.rest.bnd.library:1.2.3
529 changes: 24 additions & 505 deletions backend/cnf/local/index.xml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions backend/de.jena.udp.dashboard.edit.web.app/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
-init: \
${system-allow-fail; npm run build-only --prefix ../../../legacy.dashboard.client/}


-includeresource: \
content=-../../../legacy.dashboard.client/dist,\
content/configs=configs
content/config=config

-buildpath: \
org.osgi.annotation.bundle,\
org.osgi.service.component.annotations,\
org.osgi.service.http.whiteboard,\
org.osgi.framework,\
jakarta.servlet-api
jakarta.ws.rs-api,\
jakarta.servlet-api,\
org.osgi.service.jakartars,\
org.osgi.service.cm
9 changes: 9 additions & 0 deletions backend/de.jena.udp.dashboard.edit.web.app/config/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

(function(window) {
window.__env = window.__env || {};

window.__env.settings = {
"releaseEndPointUrl": "../../rest/dashboard/release"
};

})(this);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package de.jena.udp.dashboard.edit.web.app;

import jakarta.ws.rs.core.Application;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.jakartars.whiteboard.propertytypes.JakartarsApplicationBase;
import org.osgi.service.jakartars.whiteboard.propertytypes.JakartarsName;
import org.osgi.service.jakartars.whiteboard.propertytypes.JakartarsWhiteboardTarget;

/**
*
* @author grune
* @since Oct 1, 2024
*/
@Component(name = "DashboardRestApplication", service = Application.class, property = {"applicationId=dashboardRest"})
@JakartarsApplicationBase("/dashboard")
@JakartarsWhiteboardTarget("(jersey.jakartars.whiteboard.name=udprest)")
@JakartarsName("UDP Dashboard API")
public class DashboardRestApplication extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package de.jena.udp.dashboard.edit.web.app;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;

import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ServiceScope;
import org.osgi.service.jakartars.whiteboard.propertytypes.JakartarsApplicationSelect;
import org.osgi.service.jakartars.whiteboard.propertytypes.JakartarsResource;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

/**
*
* @author grune
* @since Oct 1, 2024
*/
@Component(service = SaveResource.class, scope = ServiceScope.PROTOTYPE)
@JakartarsResource
@JakartarsApplicationSelect("(applicationId=dashboardRest)")
@Path("/")
public class SaveResource {

@Reference
private ConfigurationAdmin configAdmin;

@GET
@Path("/hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello";
}

@POST
@Path("/release/{path}")
@Consumes(MediaType.APPLICATION_JSON)
public Response release(@PathParam("path") String path, InputStream stream) throws IOException {
byte[] bytes = stream.readAllBytes();
String dir = System.getProperty("user.dir", "/tmp");
File p = new File(dir + "/dashboards/");
p.mkdirs();
File file = new File(p, path + ".json");
try (FileOutputStream os = new FileOutputStream(file)) {
os.write(bytes);
}
Hashtable<String, Object> props = new Hashtable<>();
props.put("path", path);
props.put("configFile", file.getAbsolutePath());
Configuration configuration = configAdmin.getFactoryConfiguration("DashboardViewerConfigurator", path, "?");
configuration.updateIfDifferent(props);

return Response.ok().build();
}
}
4 changes: 2 additions & 2 deletions backend/de.jena.udp.dashboard.view.web.app/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-dependson: de.jena.udp.dashboard.edit.web.app

-includeresource: \
content=-../../../legacy.dashboard.client/dist,\
content/configs=configs
content=-../../../legacy.dashboard.client/dist

-buildpath: \
org.osgi.annotation.bundle,\
org.osgi.service.component.annotations,\
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void activate(Config config) {
String path = config.path().startsWith(PATH_SEPARATOR) ? config.path() : PATH_SEPARATOR + config.path();
path = path.endsWith(PATH_SEPARATOR) ? path.substring(0, path.length() - 2) : path;
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/html" + path);
config(props, ContentTypeServletContextHelper.COMPONENT_NAME);
props.put("configFile", config.configFile());
config(props, DashboardViewerContext.COMPONENT_NAME);

props = new Hashtable<>();
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
*/
package de.jena.udp.dashboard.viewer.web.app;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -22,25 +26,47 @@
import org.osgi.service.component.annotations.ServiceScope;
import org.osgi.service.http.context.ServletContextHelper;

@Component(name="DashboardViewerContext", service = ServletContextHelper.class, scope = ServiceScope.SINGLETON, configurationPolicy = ConfigurationPolicy.REQUIRE)
import de.jena.udp.dashboard.viewer.web.app.DashboardViewerConfigurator.Config;

@Component(name = "DashboardViewerContext", service = ServletContextHelper.class, scope = ServiceScope.SINGLETON, configurationPolicy = ConfigurationPolicy.REQUIRE)
//@HttpWhiteboardContext(name = "upd-dashboard", path = "/html/dashboard")
public class ContentTypeServletContextHelper extends ServletContextHelper {
public class DashboardViewerContext extends ServletContextHelper {
public static final String COMPONENT_NAME = "DashboardViewerContext";
private Config config;


@Activate
public ContentTypeServletContextHelper(final BundleContext ctx) {
public DashboardViewerContext(final BundleContext ctx, Config config) {
super(ctx.getBundle());
this.config = config;

}

@Override
public String getMimeType(String name) {
if(name.indexOf('.') != -1 ) {
if (name.indexOf('.') != -1) {
return MIME.get(name.substring(name.lastIndexOf(".")));
}
return null;
}


@Override
public URL getResource(String name) {
if (name.endsWith("configs/dashboard.json")) {
if (Objects.nonNull(url)) {
return url;
}
String configFile = config.configFile();
try {
url = new File(configFile).toURI().toURL();
return url;
} catch (MalformedURLException e) {
System.err.println("error creating URL from " + configFile);
return super.getResource(name);
}
}
return super.getResource(name);
}

@SuppressWarnings("serial")
private static final Map<String, String> MIME = new HashMap<String, String>() {
{
Expand Down Expand Up @@ -110,5 +136,6 @@ public String getMimeType(String name) {
put(".7z", "application/x-7z-compressed");
}
};
private URL url;

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,23 @@ public class SettingsServlet extends HttpServlet {
private static final String CONFIG_JSON = """
(function(window) {
window.__env = window.__env || {};
window.__env.settings = {
"initWithConfigurationURI": {
enabled:true,
url:"http://localhost:8080/udp/html/dashboardview/configs/irgnendnenname.json"
url:"configs/dashboard.json"
},
"viewmodeByDefault":true,
};
})(this);
""";

/*
* (non-Javadoc)
*
* @see jakarta.servlet.http.HttpServlet#doGet(jakarta.servlet.http.
* HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("hallo");
resp.setContentType("application/javascript");
resp.setStatus(200);
String config = CONFIG_JSON.formatted(getEnv("INFO_CHECK_URI"), getEnv("INFO_BASE_URI"));
String config = CONFIG_JSON;
resp.getOutputStream().print(config);
}

/**
* @param string
* @return
*/
private Object getEnv(String key) {
String env = System.getenv(key);
if (env == null) {
env = System.getProperty(key);
}
if (env == null) {
return "null";
}
return "\"" + env + "\"";
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"org.apache.felix.http.debug" : true
},
"JakartarsServletWhiteboardRuntimeComponent~udprest": {
"jersey.jakartars.whiteboard.name": "",
"jersey.jakartars.whiteboard.name": "udprest",
"jersey.context.path": "rest",
"osgi.http.whiteboard.target": "(rest=true)"
}
Expand Down
27 changes: 27 additions & 0 deletions backend/de.jena.udp.sensinact.runtime/data/ePackages.ecore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:sensinactMetadata="https://eclipse.org/sensinact/core/metadata/1.0"
name="base" nsURI="https://eclipse.org/sensinact/default" nsPrefix="sensinactBase">
<eClassifiers xsi:type="ecore:EClass" name="Sensinact" eSuperTypes="https://eclipse.org/sensinact/core/provider/1.0#//Provider">
<eAnnotations source="metadata">
<contents xsi:type="sensinactMetadata:AnnotationMetadata" timestamp="2024-10-01T14:19:27.685511794Z"/>
</eAnnotations>
<eAnnotations source="model">
<details key="name" value="sensinact"/>
</eAnnotations>
<eStructuralFeatures xsi:type="sensinactMetadata:ServiceReference" name="system"
eType="ecore:EClass data/ePackages.ecore#//System" containment="true" timestamp="2024-10-01T14:19:27.685511794Z"
locked="false" originalName="system"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="System" eSuperTypes="https://eclipse.org/sensinact/core/provider/1.0#//Service">
<eAnnotations source="metadata">
<contents xsi:type="sensinactMetadata:AnnotationMetadata" timestamp="2024-10-01T14:19:27.685511794Z"/>
</eAnnotations>
<eStructuralFeatures xsi:type="sensinactMetadata:ResourceAttribute" name="version"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble" timestamp="2024-10-01T14:19:27.685511794Z"
locked="false" originalName="version"/>
<eStructuralFeatures xsi:type="sensinactMetadata:ResourceAttribute" name="started"
eType="ecore:EDataType https://eclipse.org/sensinact/core/provider/1.0#//EInstant"
timestamp="2024-10-01T14:19:27.685511794Z" locked="false" originalName="started"/>
</eClassifiers>
</ecore:EPackage>
27 changes: 27 additions & 0 deletions backend/de.jena.udp.sensinact.runtime/data/providers.xmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="ASCII"?>
<sensinactBase:Sensinact xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:sensinactBase="https://eclipse.org/sensinact/default" xmlns:sensinactMetadata="https://eclipse.org/sensinact/core/metadata/1.0" id="sensiNact">
<admin friendlyName="sensiNact" modelPackageUri="https://eclipse.org/sensinact/default" model="sensinact">
<metadata>
<key xsi:type="ecore:EAttribute" href="https://eclipse.org/sensinact/core/provider/1.0#//Admin/friendlyName"/>
<value xsi:type="sensinactMetadata:ResourceMetadata" timestamp="2024-10-01T14:19:27.685511794Z" originalName="friendlyName"/>
</metadata>
<metadata>
<key xsi:type="ecore:EAttribute" href="https://eclipse.org/sensinact/core/provider/1.0#//Admin/modelPackageUri"/>
<value xsi:type="sensinactMetadata:ResourceMetadata" timestamp="2024-10-01T14:19:27.685511794Z" originalName="modelPackageUri"/>
</metadata>
<metadata>
<key xsi:type="ecore:EAttribute" href="https://eclipse.org/sensinact/core/provider/1.0#//Admin/model"/>
<value xsi:type="sensinactMetadata:ResourceMetadata" timestamp="2024-10-01T14:19:27.685511794Z" originalName="model"/>
</metadata>
</admin>
<system version="0.1" started="2024-10-01T14:19:27.685511794Z">
<metadata>
<key xsi:type="sensinactMetadata:ResourceAttribute" href="https://eclipse.org/sensinact/default#//System/version"/>
<value xsi:type="sensinactMetadata:ResourceMetadata" timestamp="2024-10-01T14:19:27.685511794Z"/>
</metadata>
<metadata>
<key xsi:type="sensinactMetadata:ResourceAttribute" href="https://eclipse.org/sensinact/default#//System/started"/>
<value xsi:type="sensinactMetadata:ResourceMetadata" timestamp="2024-10-01T14:19:27.685511794Z"/>
</metadata>
</system>
</sensinactBase:Sensinact>
Loading

0 comments on commit ee1bcfc

Please sign in to comment.