Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Settings(BaseSettings):
@app.post("/convert/tojson/{file_type}/", status_code=214) # 214 - Transformation applied
async def convert_to_json(file_type: str, featuremodel: UploadFile):
"""
Endpoint for converting the specified format to the CFM toolbox JSON format.
Endpoint for converting from UVL to JSON format.
"""
match file_type:
case "UVL" | "uvl":
Expand All @@ -41,6 +41,32 @@ async def convert_to_json(file_type: str, featuremodel: UploadFile):
)


async def receive_uvl_file(featuremodel: UploadFile) -> dict:
"""
Create a CFMJson from the provided UVL object.
"""
filename = generate_random_filename(8, "uvl")
result_filename = filename.replace(".uvl", ".json")
async with aiofiles.open(filename, "wb") as out_file:
while content := await featuremodel.read(1024): # Read in 1024b chunks
await out_file.write(content)
try:
call_cfm_toolbox_conversion(filename, result_filename)
except RuntimeError as e:
return Response(
content=f"Error during conversion: {str(e)}",
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
async with aiofiles.open(result_filename, "rb") as result_file:
content = await result_file.read()
featuremodel_json = json.loads(content)

# Cleanup temp files
os.remove(filename)
os.remove(result_filename)
return featuremodel_json


@app.post("/convert/fromjson/{file_type}/", status_code=214) # 214 - Transformation applied
async def convert_from_json(
file_type: str, featuremodel: CFMJson, background_tasks: BackgroundTasks
Expand Down
20 changes: 18 additions & 2 deletions frontend/cfmtoolbox-webeditor/src/app/feature-model-reactflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,24 @@ export default function FeatureModelEditor() {
}, []);

useEffect(() => {
if (mode === "demo") {
const { nodes, edges, constraints } = importFeatureModel(demoModel);
// Load Model from local storage
const nodes = localStorage.getItem("nodes");
const edges = localStorage.getItem("edges");
const constraints = localStorage.getItem("constraints");

console.log("Loaded: ", nodes, edges, constraints);

if (nodes) setNodes(JSON.parse(nodes));
if (edges) setEdges(JSON.parse(edges));
if (constraints) setConstraints(JSON.parse(constraints));
}, []);

useEffect(() => {
// Store Model in local storage
localStorage.setItem("nodes", JSON.stringify(nodes));
localStorage.setItem("edges", JSON.stringify(edges));
localStorage.setItem("constraints", JSON.stringify(constraints));
}, [nodes, edges, constraints]);

setNodes(nodes);
setEdges(edges);
Expand Down
Loading