Skip to content

Commit

Permalink
feat: add devices request
Browse files Browse the repository at this point in the history
Signed-off-by: zhiheng123 <[email protected]>
  • Loading branch information
zhiheng123 committed Oct 13, 2024
1 parent 7e20202 commit 5ff4bff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package io.github.protocol.mtconnect.api;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AssetRequest {
private String id;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package io.github.protocol.mtconnect.api;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AssetResponse {
MTConnectAssets assets;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import io.github.openfacade.http.HttpServer;
import io.github.openfacade.http.HttpServerFactory;
import io.github.openfacade.http.SyncRequestHandler;
import io.github.protocol.mtconnect.api.AssetRequest;
import io.github.protocol.mtconnect.api.AssetResponse;
import io.github.protocol.mtconnect.common.XmlUtil;
import io.netty.handler.codec.http.HttpResponseStatus;

import java.util.concurrent.CompletableFuture;

Expand All @@ -30,11 +34,16 @@ public CompletableFuture<Void> start() {
class MtAssetsHandler implements SyncRequestHandler {
@Override
public HttpResponse handle(HttpRequest request) {
// todo
// read http request to mt asset request
// call mtProcessor to get the response
AssetResponse assetResponse = mtProcessor.asset(new AssetRequest());
// convert the response to http response
return null;
String body;
try {
body = XmlUtil.toXml(assetResponse.getAssets());
} catch (Exception e) {
throw new RuntimeException(e);
}

return new HttpResponse(HttpResponseStatus.OK.code(), body.getBytes());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

import io.github.protocol.mtconnect.api.AssetRequest;
import io.github.protocol.mtconnect.api.AssetResponse;
import io.github.protocol.mtconnect.api.MTConnectAssets;
import io.github.protocol.mtconnect.server.MtProcessor;

import java.util.HashMap;
import java.util.Map;

/**
* MemoryMtProcessor is a simple implementation of MtProcessor that stores all the data in memory.
*/
public class MemoryMtProcessor implements MtProcessor {

Map<String, MTConnectAssets> mtConnectAssetsMap = new HashMap<>();

@Override
public AssetResponse asset(AssetRequest assetRequest) {
return null;
MTConnectAssets assets = mtConnectAssetsMap.get(assetRequest.getId());
AssetResponse assetResponse = new AssetResponse();
assetResponse.setAssets(assets);
return assetResponse;
}
}

0 comments on commit 5ff4bff

Please sign in to comment.