Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
249921d
added endpoints basic
MarcoDoell Feb 10, 2022
1463098
adapterEndpoint added + utils + routes for all adapter endpoints with…
MarcoDoell Feb 10, 2022
ddc408f
service adapterendpoint added / model interpreter stub added / getall…
MarcoDoell Feb 11, 2022
59bb3fe
lines
MarcoDoell Feb 11, 2022
9af42c7
Test
PVahldiek Feb 11, 2022
b87260c
test
ChristoffS Feb 11, 2022
df25c8a
revert
ChristoffS Feb 11, 2022
0b72720
added other service methods for adapterservice and models with @PVahl…
MarcoDoell Feb 11, 2022
d2a6d54
Merge branch 'adapter-nodejs-refactoring' of https://github.com/Marco…
MarcoDoell Feb 11, 2022
a3dd532
added formatconfig, format and protocol with @PVahldiek
MarcoDoell Feb 22, 2022
45799a5
interpreter start with @PVahldiek
MarcoDoell Feb 22, 2022
1429d1a
added jackson-js package for jsonproperty annotations with @PVahldiek
MarcoDoell Feb 22, 2022
fa40012
validator for first adapterendpoint method with @PVahldiek
MarcoDoell Feb 22, 2022
be7f1cb
adapterconfigvalidator with @PVahldiek
MarcoDoell Feb 22, 2022
683c799
validator for protocolConfig with @MarcoDoell
PVahldiek Feb 22, 2022
84ccb6e
removed jackson-js with @MarcoDoell
PVahldiek Feb 22, 2022
f7f4122
import ProtocolConfigValidator in adapterEndpoint with @MarcoDoell
PVahldiek Feb 22, 2022
d70c9c3
added interpreter implementation classes with @MarcoDoell
PVahldiek Feb 22, 2022
237999e
added interpreter implementation classes with @MarcoDoell
PVahldiek Feb 22, 2022
1bb6385
export classes
MarcoDoell Feb 22, 2022
1ef3aaf
emulate object enums with class since typescript does only support nu…
MarcoDoell Feb 22, 2022
faa0a05
protocol class instead of enum with @PVahldiek
MarcoDoell Feb 22, 2022
ac70d7f
refacotring code review with @PVahldiek
MarcoDoell Feb 24, 2022
5afd1a5
get all formats and get all protocols + added importer classes
MarcoDoell Feb 24, 2022
8d0a49b
importer classes with @PVahldiek
MarcoDoell Feb 24, 2022
7e6ef78
protocol with @PVahldiek
MarcoDoell Feb 24, 2022
eb68abf
importer implement methods with @PVahldiek
MarcoDoell Feb 24, 2022
2ddc14d
interpreter with @PVahldiek
MarcoDoell Feb 24, 2022
a3ba295
inherit methods from abstract class with @PVahldiek
MarcoDoell Feb 24, 2022
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

SPDX-License-Identifier: AGPL-3.0-only

Binary file added __pycache__/oneuser.cpython-310.pyc
Binary file not shown.
68 changes: 67 additions & 1 deletion adapter/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions adapter/src/api/rest/adapterEndpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import express from 'express';
import { AdapterConfigValidator } from '../../model/AdapterConfig';


import { asyncHandler } from './utils';
import {ProtocolConfigValidator} from "../../model/ProtocolConfig";
import { Format } from '../../model/enum/Format';

const adapterService = require( "../../services/AdapterService" );
const APP_VERSION = "0.0.1"
export class AdapterEndpoint {
constructor() {}

registerRoutes = (app: express.Application): void => {
app.post('/preview', asyncHandler(this.handleExecuteDataImport));
app.post('/preview/raw', asyncHandler(this.handleExecuteRawPreview));
app.get('/formats', asyncHandler(this.handleGetFormat));
app.get('/protocols', asyncHandler(this.handleGetProtocols));
app.get('/version', asyncHandler(this.handleGetApplicationVersion));
};

// Adapter Endpoint
/**
* @RestController
@AllArgsConstructor
public class AdapterEndpoint {
private final Adapter adapter;

@PostMapping(Mappings.IMPORT_PATH)
public DataImportResponse executeDataImport(@Valid @RequestBody AdapterConfig config)
throws ImporterParameterException, InterpreterParameterException, IOException {
return adapter.executeJob(config);
}

@PostMapping(Mappings.RAW_IMPORT_PATH)
public DataImportResponse executeRawPreview(@Valid @RequestBody ProtocolConfig config)
throws ImporterParameterException {
return adapter.executeRawImport(config);
}
}
*/

handleExecuteDataImport = async (
req: express.Request,
res: express.Response,
): Promise<void> => {
const validator = new AdapterConfigValidator();
if (!validator.validate(req.body)) {
res.status(400).json({ errors: validator.getErrors() });
return;
}

let adapterConfig = req.params.config
let returnDataImportResponse = adapterService.executeJob(adapterConfig);
res.status(200).send(returnDataImportResponse);
};

handleExecuteRawPreview = async (
req: express.Request,
res: express.Response,
): Promise<void> => {
const validator = new ProtocolConfigValidator();
if (!validator.validate(req.body)) {
res.status(400).json({ errors: validator.getErrors() });
return;
}
let protocolConfig = req.params.config
let returnDataImportResponse = adapterService.executeRawImport(protocolConfig);
res.status(200).send(returnDataImportResponse);
};

/*
returns Collection of Importer
} */

handleGetFormat = async (
req: express.Request,
res: express.Response,
): Promise<void> => {
try {
let interpreters = adapterService.getAllFormats();
res.status(200).json(interpreters);
} catch (e) {
res.status(500).send('Error finding formats');
}
};

/*
returns Collection of Importer
*/
handleGetProtocols = async (
req: express.Request,
res: express.Response,
): Promise<void> => {
try {
let protocols = adapterService.getAllProtocols();
res.status(200).json(protocols);
} catch (e) {
res.status(500).send('Error finding protocols');
}
};

handleGetApplicationVersion = async (
req: express.Request,
res: express.Response,
): Promise<void> => {
res.status(200).send(APP_VERSION);
};
};
19 changes: 19 additions & 0 deletions adapter/src/api/rest/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { NextFunction, Request, RequestHandler, Response } from 'express';

/**
* A wrapper for promise returning request handlers that passes the value of a
* rejected promise to express's `next` function.
* @param handler request handler to wrap
*/
export function asyncHandler(
handler: (
req: Request,
res: Response,
next?: NextFunction,
) => void | Promise<void>,
): RequestHandler {
return (req: Request, res: Response, next: NextFunction): void => {
const handlerResult = handler(req, res, next);
Promise.resolve(handlerResult).catch(next);
};
}
63 changes: 63 additions & 0 deletions adapter/src/importer/HttpImporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Importer } from "./Importer";
import { ImporterParameterDescription } from "./ImporterParameterDescription";

export class HttpImporter extends Importer {
getAvailableParameters(): ImporterParameterDescription[] {
throw new Error("Method not implemented.");
}
doFetch(parameters: Record<string, unknown>): string {
throw new Error("Method not implemented.");
}
/**
*
* private final List<ImporterParameterDescription> parameters = List.of(
new ImporterParameterDescription("location", "String of the URI for the HTTP call", String.class),
new ImporterParameterDescription("encoding",
"Encoding of the source. Available encodings: ISO-8859-1, US-ASCII, UTF-8", String.class),
new ImporterParameterDescription("defaultParameters", "Default values for open parameters in the URI", false,
RuntimeParameters.class));
private final RestTemplate restTemplate;

@Override
public String getType() {
return "HTTP";
}

@Override
public String getDescription() {
return "Plain HTTP";
}

@Override
protected void validateParameters(Map<String, Object> inputParameters) throws ImporterParameterException {
super.validateParameters(inputParameters);

String encoding = (String) inputParameters.get("encoding");
if (!encoding.equals(StandardCharsets.ISO_8859_1.name()) && !encoding.equals(StandardCharsets.US_ASCII.name()) && !encoding.equals(StandardCharsets.UTF_8.name())) {
throw new IllegalArgumentException(getType() + " interpreter requires parameter encoding to have value " +
StandardCharsets.ISO_8859_1 + ", " +
StandardCharsets.US_ASCII + ", " +
StandardCharsets.UTF_8
+ ". Your given value " + encoding + " is invalid!");
}
}

@Override
public List<ImporterParameterDescription> getAvailableParameters() {
return parameters;
}

@Override
protected String doFetch(Map<String, Object> parameters) throws ImporterParameterException {
String location = parameters.get("location").toString();
try {
URI uri = URI.create(location);
byte[] rawResponse = restTemplate.getForEntity(uri, byte[].class).getBody();
return new String(rawResponse, Charset.forName((String) parameters.get("encoding")));
} catch (IllegalArgumentException e) {
throw new ImporterParameterException(e.getMessage());
}
}
*/

}
Loading