Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static void main(String[] args) {
IoTDAMtProcessor ioTDAMtProcessor = new IoTDAMtProcessor.Builder()
.setAk(System.getenv("CLOUD_SDK_AK"))
.setSk(System.getenv("CLOUD_SDK_SK"))
.setProjectId("your_project_id")
.setEndpoint("ec138732b4.st1.iotda-app.cn-north-4.myhuaweicloud.com")
.setEndpoint(System.getenv("CLOUD_SDK_ENDPOINT"))
.build();

configuration.setMtProcessor(ioTDAMtProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@
import com.huaweicloud.sdk.iotda.v5.IoTDAClient;
import com.huaweicloud.sdk.iotda.v5.model.ListDevicesRequest;
import com.huaweicloud.sdk.iotda.v5.model.ListDevicesResponse;
import com.huaweicloud.sdk.iotda.v5.model.QueryDeviceSimplify;
import io.github.protocol.mtconnect.api.AssetRequest;
import io.github.protocol.mtconnect.api.Device;
import io.github.protocol.mtconnect.api.DeviceRequest;
import io.github.protocol.mtconnect.api.MTConnectAssets;
import io.github.protocol.mtconnect.api.MTConnectDevices;
import io.github.protocol.mtconnect.server.MTProcessor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

@Slf4j
@NoArgsConstructor
public class IoTDAMtProcessor implements MTProcessor {
private String ak;
private String sk;
private String projectId;
private String endpoint;
private IoTDAClient client;

Expand All @@ -32,11 +35,19 @@
return null;
}

private Device convert2MTDevice(QueryDeviceSimplify deviceSimplify) {
Device device = new Device();
device.setId(deviceSimplify.getDeviceId());
device.setName(deviceSimplify.getDeviceName());
return device;

Check warning on line 42 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L39-L42

Added lines #L39 - L42 were not covered by tests
}

@Override
public MTConnectDevices device(DeviceRequest deviceRequest) {
ListDevicesRequest request = new ListDevicesRequest();
ListDevicesResponse response = null;

Check warning on line 48 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L48

Added line #L48 was not covered by tests
try {
ListDevicesResponse response = client.listDevices(request);
response = client.listDevices(request);

Check warning on line 50 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L50

Added line #L50 was not covered by tests
log.info(response.toString());
} catch (ConnectionException | RequestTimeoutException e) {
log.error(e.getMessage());
Expand All @@ -46,8 +57,18 @@
log.error(e.getRequestId());
log.error(e.getErrorCode());
log.error(e.getErrorMsg());
return null;

Check warning on line 60 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L60

Added line #L60 was not covered by tests
}
return null;

MTConnectDevices mtConnectDevices = new MTConnectDevices();
ArrayList<Device> devices = new ArrayList<>();

Check warning on line 64 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L63-L64

Added lines #L63 - L64 were not covered by tests
if (response != null) {
for (QueryDeviceSimplify deviceSimplify : response.getDevices()) {
devices.add(convert2MTDevice(deviceSimplify));
}

Check warning on line 68 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L67-L68

Added lines #L67 - L68 were not covered by tests
}
mtConnectDevices.setDevices(devices);
return mtConnectDevices;

Check warning on line 71 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/impl/IoTDAMtProcessor.java#L70-L71

Added lines #L70 - L71 were not covered by tests
}

public static class Builder {
Expand All @@ -62,11 +83,6 @@
return this;
}

public Builder setProjectId(String projectId) {
ioTDAMtProcessor.projectId = projectId;
return this;
}

public Builder setEndpoint(String endpoint) {
ioTDAMtProcessor.endpoint = endpoint;
return this;
Expand Down