Skip to content

Commit

Permalink
mainly organisational changes
Browse files Browse the repository at this point in the history
- simplify ora.sh as Docker got its own repo
- move /transform in a RESR entity of its own
- improve README (after executing all steps, which
  implicitly changes the package-lock files of npm
  • Loading branch information
rbudde committed Aug 6, 2023
1 parent cf94892 commit 73fbf1c
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 330 deletions.
99 changes: 1 addition & 98 deletions Contributing.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,3 @@
# Contributing Guidelines

We want to make it as simple as possible for our users and contributors to reach us and communicate with one another, so that the Open Roberta Lab can continue to improve. Here are our key channels right now; we'd love to hear from you on one of them.

## Google Group

[Open Roberta Google Group](https://groups.google.com/g/open-roberta)

If you have a general inquiry about the Open Roberta Lab, the Open Roberta Google Group is a good place to start. It's also a good place to express the roadmap or upcoming new features.

## Gitter

[Open Roberta Lab - Gitter](https://gitter.im/openroberta-lab/community)

For our developer community, we use Gitter. You are welcome to join the group.

## Github

[Open Roberta Issues](https://github.com/OpenRoberta/openroberta-lab/issues)

Please file an issue in our main GitHub project (OpenRoberta/robertalab) if you find a bug.

The Open Roberta Google Group (see above) is probably a better place to start if you want to brainstorm a potential new feature.

## Development

This document provides a collection of instructions that will assist you with the contribution process.
We gratefully accept all contributions from anyone who wishes to improve/add new functionality to this project or resolve bugs.

Below you will find the process and workflow for contributing to Open Roberta lab.

## Step 1 : Find an issue
- Take a look at the Existing Issues or create your **own** Issues!
- Ask for the Issue to be assigned to you after which you can start working on it.
- Note : Every change in this project should/must have an associated issue.

## Step 2 : Fork the Project
- Fork this Repository. This will create a Local Copy of this Repository on your Github Profile. Keep a reference to the original project in `upstream` remote.
.
- Development happens in the [develop branch](https://github.com/OpenRoberta/openroberta-lab/tree/develop). Please send PRs against that branch.
```
$ git clone https://github.com/<Your username>/openroberta-lab.git
$ cd openroberta-lab
$ git remote add upstream https://github.com/OpenRoberta/openroberta-lab.git
```

- If you have already forked the project, update your copy before working.
```
$ git remote update
$ git checkout <branch-name>
$ git rebase upstream/<branch-name>
```
## Step 3 : Branch
Create a new branch. Use its name to identify the issue you are addressing.
```
# It will create a new branch with name Branch_Name and switch to that branch
$ git checkout -b branch_name
```
## Step 4 : Work on the issue assigned
- Work on the issue(s) assigned to you.
- Add all the files/folders needed.
- After you've made changes or made your contribution to the project add changes to the branch you've just created by:
```
# To add all new files to branch Branch_Name
$ git add .
```
## Step 5 : Commit
- A good commit message focuses on the `why` instead of the `what`.
```
# This message get associated with all files you have changed
$ git commit -m "message"
```
## Step 6 : Work Remotely
- Now you are ready to your work to the remote repository.
- When your work is ready and complies with the project conventions, upload your changes to your fork:

```
# To push your work to your remote repository
$ git push -u origin Branch_Name
```

## Step 7 : Pull Request
- Go to your repository in browser and click on compare and pull requests. Then add a title and description to your pull request that explains your contribution.

- Voila! Your Pull Request has been submitted and will be reviewed by the moderators/admins/project manger.

You can follow the test status [here](https://travis-ci.org/github/OpenRoberta).

## Need more help?
You can refer to the following articles on basics of Git and Github and also contact the Project Mentors, in case you are stuck:
- [Forking a Repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
- [Cloning a Repo](https://help.github.com/en/desktop/contributing-to-projects/creating-an-issue-or-pull-request)
- [How to create a Pull Request](https://opensource.com/article/19/7/create-pull-request-github)
- [Getting started with Git and GitHub](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6)
- [Learn GitHub from Scratch](https://lab.github.com/githubtraining/introduction-to-github)

Please read [Open Roberta Github Wiki Community](https://github.com/OpenRoberta/openroberta-lab/wiki/Community)
Original file line number Diff line number Diff line change
Expand Up @@ -480,42 +480,6 @@ public Response importProgram(@XsltTrans XsltTransformer xsltTransformer, FullRe
return UtilForREST.makeBaseResponseForError(Key.PROGRAM_IMPORT_ERROR, httpSessionState, null);
}

@POST
@Path("/transform")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response transform(@XsltTrans XsltTransformer xsltTransformer, String toTransform) {
String transformed = "";
try {
toTransform = UtilForHtmlXml.checkProgramTextForXSS(toTransform);
toTransform = xsltTransformer.transform(toTransform);
if ( toTransform != null ) {
Export jaxbImportExport = JaxbHelper.xml2Element(toTransform, Export.class);
if ( jaxbImportExport != null ) {
String robotType1 = jaxbImportExport.getProgram().getBlockSet().getRobottype();
String robotType2 = jaxbImportExport.getConfig().getBlockSet().getRobottype();
RobotFactory robotFactory = getArbitraryPluginOfAPluginGroup(robotType1, robotPluginMap);
if ( robotFactory != null && robotType1.equals(robotType2) ) {
BlockSet jaxbProgram = jaxbImportExport.getProgram().getBlockSet();
checkAndAddNnDataForPlugin(robotFactory.getPluginProperties().getRobotName(), jaxbProgram);
String progXml = JaxbHelper.blockSet2xml(jaxbProgram);
String configXml = JaxbHelper.blockSet2xml(jaxbImportExport.getConfig().getBlockSet());
Pair<String, String> progConfPair =
UtilForXmlTransformation.transformBetweenVersions(robotFactory, jaxbProgram.getXmlversion(), progXml, configXml);
progXml = progConfPair == null ? progXml : progConfPair.getFirst();
configXml = progConfPair == null ? configXml : progConfPair.getSecond();
transformed = "<export xmlns=\"http://de.fhg.iais.roberta.blockly\"><program>" + progXml + "</program><config>" + configXml + "</config></export>";
Statistics.info("ProgramTransForm", "success", true);
}
}
}
} catch ( Exception e ) {
transformed = "";
Statistics.info("ProgramTransForm", "success", false);
}
return Response.ok(transformed).build();
}

/**
* used to export all Programs of every robot of the current user.
* To get give appropriate feedback logincheck from ClientUser.java should be called before this.
Expand Down Expand Up @@ -833,15 +797,6 @@ private static String getRobot(HttpSessionState httpSessionState) {
: httpSessionState.getRobotFactory(httpSessionState.getRobotName()).getGroup();
}

private RobotFactory getArbitraryPluginOfAPluginGroup(String pluginNameOrPluginGroup, Map<String, RobotFactory> robotPluginMap) {
for ( RobotFactory robotPlugin : robotPluginMap.values() ) {
if ( pluginNameOrPluginGroup.equals(robotPlugin.getGroup()) ) {
return robotPlugin;
}
}
return null;
}

private void checkAndAddNnDataForPlugin(String robotName, BlockSet jaxbImportExport) {
if ( this.robotPluginMap.get(robotName).hasNN() ) {
for ( Instance instance : jaxbImportExport.getInstance() ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package de.fhg.iais.roberta.javaServer.restServices.all.controller;

import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;
import com.google.inject.name.Named;

import de.fhg.iais.roberta.blockly.generated.BlockSet;
import de.fhg.iais.roberta.blockly.generated.Export;
import de.fhg.iais.roberta.factory.RobotFactory;
import de.fhg.iais.roberta.javaServer.provider.OraData;
import de.fhg.iais.roberta.javaServer.provider.XsltTrans;
import de.fhg.iais.roberta.persistence.ProgramProcessor;
import de.fhg.iais.roberta.persistence.bo.Program;
import de.fhg.iais.roberta.persistence.dao.ProgramDao;
import de.fhg.iais.roberta.persistence.util.DbSession;
import de.fhg.iais.roberta.util.ServerProperties;
import de.fhg.iais.roberta.util.Statistics;
import de.fhg.iais.roberta.util.UtilForHtmlXml;
import de.fhg.iais.roberta.util.UtilForXmlTransformation;
import de.fhg.iais.roberta.util.XsltTransformer;
import de.fhg.iais.roberta.util.basic.Pair;
import de.fhg.iais.roberta.util.dbc.DbcException;
import de.fhg.iais.roberta.util.jaxb.JaxbHelper;

@Path("/transform")
public class ClientTransformController {
private static final Logger LOG = LoggerFactory.getLogger(ClientTransformController.class);

private final Map<String, RobotFactory> robotPluginMap;
private final boolean feature_Toggle_loadProgramTransformSaveProgram;

@Inject
public ClientTransformController(ServerProperties serverProperties, @Named("robotPluginMap") Map<String, RobotFactory> robotPluginMap) {
this.feature_Toggle_loadProgramTransformSaveProgram =
serverProperties.getBooleanProperty("feature-toggle.load-program-transform-save-program");
this.robotPluginMap = robotPluginMap;
}

@POST
@Path("/program")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response transform(@XsltTrans XsltTransformer xsltTransformer, String toTransform) {
String transformed = "";
try {
toTransform = UtilForHtmlXml.checkProgramTextForXSS(toTransform);
toTransform = xsltTransformer.transform(toTransform);
if ( toTransform != null ) {
Export jaxbImportExport = JaxbHelper.xml2Element(toTransform, Export.class);
if ( jaxbImportExport != null ) {
BlockSet jaxbProgram = jaxbImportExport.getProgram().getBlockSet();
BlockSet jaxbConfig = jaxbImportExport.getConfig().getBlockSet();
String robotType1 = jaxbProgram.getRobottype();
String robotType2 = jaxbConfig.getRobottype();
RobotFactory robotFactory = getArbitraryPluginOfAPluginGroup(robotType1, robotPluginMap);
if ( robotFactory != null && robotType1.equals(robotType2) ) {
String progXml = JaxbHelper.blockSet2xml(jaxbProgram);
String configXml = JaxbHelper.blockSet2xml(jaxbConfig);
Pair<String, String> progConfPair = UtilForXmlTransformation.transformBetweenVersions(robotFactory, jaxbProgram.getXmlversion(), progXml, configXml);
progXml = progConfPair == null ? progXml : progConfPair.getFirst();
configXml = progConfPair == null ? configXml : progConfPair.getSecond();
transformed = "<export xmlns=\"http://de.fhg.iais.roberta.blockly\"><program>" + progXml + "</program><config>" + configXml + "</config></export>";
Statistics.info("ProgramTransForm", "success", true);
}
}
}
} catch ( Exception e ) {
transformed = "";
Statistics.info("ProgramTransForm", "success", false);
}
return Response.ok(transformed).build();
}

@POST
@Path("/idList")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response transformIdList(@XsltTrans XsltTransformer xsltTransformer, @OraData DbSession dbSession, String idsToTransformAsString) {
if ( !feature_Toggle_loadProgramTransformSaveProgram ) {
throw new DbcException("feature toggle, that allows program transformations from the db is disabled");
}
RobotFactory robotFactory = getArbitraryPluginOfAPluginGroup("calliope2017NoBlue", robotPluginMap);
String[] idsToTransform = idsToTransformAsString.split("\\s*,\\s*");
LOG.error("transforming " + idsToTransform.length + " programs from the database");
ProgramProcessor programProcessor = new ProgramProcessor(dbSession, 0);
ProgramDao programDao = new ProgramDao(dbSession);
String transformMessage = "undefined";
try {
for ( String idToTransform : idsToTransform ) {
LOG.error(idToTransform);
Program programToTransform = programDao.load(Integer.parseInt(idToTransform));
if ( programToTransform == null ) {
throw new DbcException("program from the db to be transformed was not found. Id: " + idToTransform);
} else {
String configName = programToTransform.getConfigName();
String programText = programToTransform.getProgramText();
String configText = programProcessor.getProgramsConfig(programToTransform);
programText = xsltTransformer.transform(programText);
if ( configText != null ) {
configText = xsltTransformer.transform(configText);
}
Pair<String, String> progConfPair = UtilForXmlTransformation.transformBetweenVersions(robotFactory, "transform!", programText, configText);
programText = progConfPair == null ? programText : progConfPair.getFirst();
configText = progConfPair == null ? configText : configName == null && configText == null ? null : progConfPair.getSecond();
programProcessor.replaceTransformedProgram(programToTransform, programText, configName, configText); // save the transformed program text and conf
Statistics.info("ProgramTransForm", "message", programProcessor.getMessage().toString());
}
}
transformMessage = "\ntransform seems to have been successful";
} catch ( Exception e ) {
transformMessage = "\ntransform crashed with exception: " + e.getMessage();
}
return Response.ok(transformMessage).build();
}

private RobotFactory getArbitraryPluginOfAPluginGroup(String pluginNameOrPluginGroup, Map<String, RobotFactory> robotPluginMap) {
for ( RobotFactory robotPlugin : robotPluginMap.values() ) {
if ( pluginNameOrPluginGroup.equals(robotPlugin.getGroup()) ) {
return robotPlugin;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ username = [email protected]
password =
# feature toggles
feature-toggle.rewrite-transformed-programs-into-the-database = false
feature-toggle.load-program-transform-save-program = false
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ public void setupTest() throws Exception {
this.sessionFactoryWrapper = tc.getSessionFactoryWrapper();
this.memoryDbSetup = tc.getMemoryDbSetup();

ServerStarter.initLoggingBeforeFirstUse(EMPTY_STRING_LIST.toArray(new String[0]));
this.robotPlugins = ServerStarter.configureRobotPlugins(this.robotCommunicator, this.serverProperties, EMPTY_STRING_LIST);

this.restUser = new ClientUser(this.robotCommunicator, this.serverProperties, null);
this.restProject = new ClientProgramController(this.serverProperties, null);
this.restProject = new ClientProgramController(this.serverProperties, robotPlugins);
this.restBlocks = new ClientAdmin(this.robotCommunicator, this.serverProperties);
this.downloadJar = new RobotDownloadProgram(this.robotCommunicator, this.serverProperties);
this.brickCommand = new RobotCommand(this.robotCommunicator);
this.theProgramOfAllUserLol = Resources.toString(PerformanceUserIT.class.getResource("/restInterfaceTest/action_BrickLight.xml"), Charsets.UTF_8);
this.executorService = Executors.newFixedThreadPool(PerformanceUserIT.MAX_PARALLEL_USERS + 10);

ServerStarter.initLoggingBeforeFirstUse(EMPTY_STRING_LIST.toArray(new String[0]));
this.robotPlugins = ServerStarter.configureRobotPlugins(this.robotCommunicator, this.serverProperties, EMPTY_STRING_LIST);
}

@After
Expand Down
Loading

0 comments on commit 73fbf1c

Please sign in to comment.