Commit f6a05c89 authored by Jean-Didier's avatar Jean-Didier
Browse files

improvement json transformation support

parent 94e0ea2d
#
# Copyright (C) 2017 7bulls.com
#
# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL
# was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
#hostname where CDO Server resides
host=cdoserver
#port on which CDO Server listens
port=2036
#the name of the CDO repository of the server
repository=repo1
#logging to be set off or on - default is off
logging=on
#user information
userName=admin
password=admin
#mysql connection properties
dbtype=mysql
dburl=jdbc:mysql://localhost:3306/repo1
username=root
password=admin
#hsqldb connection properties
#dbtype=hsqldb
#dburl=jdbc:hsqldb:file:cdohibernate
#username=admin
#password=admin
#name of the repository to be created
repository=repo1
#type of store to be created
storetype=db
#number of port to listen
port=2036
#logging should be set on or off - default is off
logging=on
#security should be set on or off - default is off
security=off
### logback configuration ###
logging.config=file:${MELODIC_CONFIG_DIR}/logback-conf/logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2017 7bulls.com
~
~ This Source Code Form is subject to the terms of the
~ Mozilla Public License, v. 2.0. If a copy of the MPL
~ was not distributed with this file, You can obtain one at
~ http://mozilla.org/MPL/2.0/.
-->
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="eu.melodic.upperware.adapter" level="INFO"/>
<logger name="org.springframework.web.filter.CommonsRequestLoggingFilter" level="DEBUG"/>
<logger name="eu.melodic.upperware.cpsolver" level="INFO"/>
<!-- choco solver begin -->
<logger name="choco" level="WARN"/>
<logger name="choco.util" level="INFO"/>
<logger name="bench" level="info"/>
<logger name="solver" level="info"/>
<logger name="fzn" level="info"/>
<logger name="explainer" level="info"/>
<logger name="configuration" level="info"/>
<logger name="tree" level="info"/>
<logger name="visualization" level="info"/>
<!-- choco solver end -->
<logger name="eu.melodic.upperware.metasolver" level="INFO"/>
<!-- from generator -->
<logger name="eu.paasage.upperware.profiler" level="INFO"/>
<logger name="eu.paasage.upperware.security" level="INFO"/>
<logger name="eu.melodic.security.authorization" level="INFO"/>
<logger name="eu.paasage.mddb.cdo.server" level="DEBUG"/>
<logger name="org.hibernate.SQL" level="DEBUG"/>
<logger name="org.hibernate.type" level="TRACE"/>
<logger name="eu.paasage.upperware.profiler.generator.service.camel" level="DEBUG"/>
<!-- DLMSWebService -->
<logger name="eu.melodic.upperware.dlms" level="DEBUG"/>
<!-- DLMSController, DLMSUtility -->
<logger name="eu.melodic.dlms" level="DEBUG"/>
<!-- ems -->
<logger name="eu.melodic.event" level="INFO"/>
<logger name="eu.melodic.event.control" level="INFO"/>
<logger name="eu.melodic.event.baguette.server" level="INFO"/>
<logger name="eu.melodic.event.baguette.client.install" level="DEBUG"/>
<logger name="eu.melodic.event.brokercep" level="DEBUG"/>
<logger name="eu.melodic.event.brokerclient" level="DEBUG"/>
<logger name="eu.melodic.event.translate" level="DEBUG"/>
<logger name="eu.melodic.event.util" level="DEBUG"/>
<logger name="eu.melodic.event.util.NetUtil" level="INFO"/>
</configuration>
......@@ -4,11 +4,34 @@ services:
image: jdtotow/camel_converter
build:
context: .
container_name: camel_converter
restart: always
container_name: camel
ports:
- 7676:7676
environment:
- PAASAGE_CONFIG_DIR=.paasage #please change it or remove it
- CDO_RESOURCE_PATH=/cdo_path #please change it
- CDO_SERVER_PATH=resource #please change it
- PAASAGE_CONFIG_DIR=.paasage
volumes:
- ./models:/app/src/models
- ./morphemic/camel_converter:/app/src/models
- ./config:/app/src/.paasage
cdoserver:
image: gitlab.ow2.org:4567/melodic/model-repository/cdo-server:rc3.1
container_name: cdoserver
volumes:
- ./tmp:/var/lib/mysql
- ./config:/config
- ./logs:/logs
environment:
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=repo1
- MYSQL_USER=root
- MYSQL_PASSWORD=admin
- MELODIC_CONFIG_DIR=/config
- PAASAGE_CONFIG_DIR=/config
- spring.config.location=/config/eu.paasage.mddb.cdo.server.properties
- LOG_FILE=/logs/cdoserver.log
pid: host
ports:
- 2036:2036
- 3306:3306
2022-06-03 10:52:00.775 INFO 62767 --- [main] e.p.m.cdo.server.CdoServerApplication : Starting CdoServerApplication v3.1.0-SNAPSHOT on 3956130dcb06 with PID 62767 (/server.jar started by root in /)
2022-06-03 10:52:00.783 DEBUG 62767 --- [main] e.p.m.cdo.server.CdoServerApplication : Running with Spring Boot v1.5.4.RELEASE, Spring v4.3.9.RELEASE
2022-06-03 10:52:00.785 INFO 62767 --- [main] e.p.m.cdo.server.CdoServerApplication : No active profile set, falling back to default profiles: default
2022-06-03 10:52:00.893 INFO 62767 --- [main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4ee285c6: startup date [Fri Jun 03 10:52:00 CEST 2022]; root of context hierarchy
2022-06-03 10:52:01.527 INFO 62767 --- [main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2022-06-03 10:52:02.583 INFO 62767 --- [main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2022-06-03 10:52:02.617 INFO 62767 --- [main] e.p.m.cdo.server.CdoServerApplication : Started CdoServerApplication in 2.647 seconds (JVM running for 3.505)
import json, time, os, uvicorn
import json, time, os, uvicorn, xmltodict
from fastapi import FastAPI
from loader import CDOClientWapper
from pydantic import BaseModel
from typing import Optional
model_folder = os.environ.get("MODEL_FOLDER","./models")
model_folder = os.environ.get("MODEL_FOLDER","./models/")
class ExportRequest(BaseModel):
resource_name: str
filename: str
output: Optional[str] = 'xmi'
class ImportRequest(BaseModel):
resource_name: str
......@@ -18,12 +20,17 @@ app = FastAPI()
@app.post("/import_model")
async def import_model(request: ImportRequest):
filename = model_folder + request.filename
if not os.path.isfile(filename):
return {"status": False, "message": "File {0} not found".format(filename)}
try:
client = CDOClientWapper()
status = client.importModel(filename, request.resource_name)
return {"response": status}
if status:
return {"status": True, "message": "camel imported successfully"}
else:
return {"status": False, "message": "An error occured while importing camel model"}
except Exception as e:
return {"response": "error", "message": e}
return {"status": False, "message": e}
@app.post("/export_model")
async def export_model(request: ExportRequest):
......@@ -31,9 +38,20 @@ async def export_model(request: ExportRequest):
try:
client = CDOClientWapper()
status = client.exportModel(filename, request.resource_name)
return {"response": status}
if status:
if request.output == "json":
_file = open(filename,"r")
_json_content = json.dumps(xmltodict.parse(_file.read()))
_file.close()
filename = filename[:filename.rindex(".")] + ".json"
_file = open(filename,"w")
_file.write(_json_content)
_file.close()
return {"status": True, "message": "Camel model exporter in the following path: {0}".format(filename)}
else:
return {"status": False, "message": ""}
except Exception as e:
return {"response": "error", "message": e}
return {"status": False, "message": e}
if __name__ == "__main__":
......
import os
os.environ["CLASSPATH"] = "./lib/client-repackaged.jar"
import os, xmltodict
import jnius_config
os.environ['PAASAGE_CONFIG_DIR'] = os.environ.get("PAASAGE_CONFIG_DIR",".paasage")
jnius_config.add_classpath("./lib/*")
from jnius import autoclass
CDOClientClass = autoclass("eu.paasage.mddb.cdo.client.CDOClient")
resource_path = os.environ.get("CDO_RESOURCE_PATH","./resource")
class CDOClientWapper():
def __init__(self, username=None, password=None):
......@@ -21,10 +19,16 @@ class CDOClientWapper():
self.cdo_client = CDOClientClass()
def importModel(self, filename, resource_name):
full_path = resource_path + resource_name
return self.cdo_client.importModel(filename, full_path, True) #True for validating model before storing
print("Exporting camel from file: {0}, to the resource name {1}".format(filename, resource_name))
return self.cdo_client.importModel(filename, resource_name, True) #True for validating model before storing
def exportModel(self, filename, resource_name):
full_path = resource_path + resource_name
return self.cdo_client.exportModel(full_path, filename)
print('Exporting camel model from resource name {0} to the file path {1}'.format(resource_name, filename))
return self.cdo_client.exportModel(resource_name, filename)
if __name__ == "__main__":
client = CDOClientWapper()
#status = client.importModel("morphemic/camel_converter/camel.xmi","my_path")
status = client.exportModel("morphemic/camel_converter/exported.xmi","my_path_1")
print(status)
import requests, json
import requests, json, time
url_camel_converter = "http://localhost:7676/import_model"
_request = {"filename": "camel-1.xmi", "resource_name": "res-name"}
_request = {"filename": "camel.xmi", "resource_name": "initialcamel"}
response = requests.post(url=url_camel_converter, data=json.dumps(_request), headers={"Content-type": "application/json"})
print(response.text)
time.sleep(60)
url_camel_converter = "http://localhost:7676/export_model"
_request = {"filename": "camel-exported-api-2.xmi", "resource_name": "initialcamel"}
response = requests.post(url=url_camel_converter, data=json.dumps(_request), headers={"Content-type": "application/json"})
print(response.text)
\ No newline at end of file
print(response.text)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment