Search in sources :

Example 1 with ProtoImport

use of org.openlca.proto.io.input.ProtoImport in project olca-modules by GreenDelta.

the class DataUpdateService method put.

@Override
public void put(ProtoDataSet dataSet, StreamObserver<ProtoRef> resp) {
    var statusRef = new ImportStatus[1];
    new ProtoImport(DataUtil.readerOf(dataSet), db).withUpdateMode(UpdateMode.ALWAYS).withStatusHandler(s -> statusRef[0] = s).run();
    var status = statusRef[0];
    if (status == null) {
        Response.invalidArg(resp, "No model in data set found");
        return;
    }
    if (status.isError()) {
        Response.serverError(resp, "Import error: " + status.error());
        return;
    }
    var ref = Refs.refOf(status.model());
    resp.onNext(ref.build());
    resp.onCompleted();
}
Also used : Empty(com.google.protobuf.Empty) Refs(org.openlca.proto.io.output.Refs) Strings(org.openlca.util.Strings) StreamObserver(io.grpc.stub.StreamObserver) IDatabase(org.openlca.core.database.IDatabase) DataUpdateServiceGrpc(org.openlca.proto.grpc.DataUpdateServiceGrpc) UpdateMode(org.openlca.jsonld.input.UpdateMode) ProtoRef(org.openlca.proto.ProtoRef) DeleteRequest(org.openlca.proto.grpc.DeleteRequest) ProtoDataSet(org.openlca.proto.grpc.ProtoDataSet) ImportStatus(org.openlca.proto.io.input.ImportStatus) ProtoImport(org.openlca.proto.io.input.ProtoImport) ImportStatus(org.openlca.proto.io.input.ImportStatus) ProtoImport(org.openlca.proto.io.input.ProtoImport)

Example 2 with ProtoImport

use of org.openlca.proto.io.input.ProtoImport in project olca-modules by GreenDelta.

the class ImportExample method main.

public static void main(String[] args) {
    var zipPath = "C:/Users/ms/Desktop/rems/test_json.zip";
    var dbPath = "C:/Users/ms/openLCA-data-1.4/databases/proto_test";
    try (var store = ZipStore.open(new File(zipPath));
        var db = new Derby(new File(dbPath))) {
        var imp = new ProtoImport(store, db);
        imp.run();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Derby(org.openlca.core.database.Derby) ProtoImport(org.openlca.proto.io.input.ProtoImport) File(java.io.File)

Aggregations

ProtoImport (org.openlca.proto.io.input.ProtoImport)2 Empty (com.google.protobuf.Empty)1 StreamObserver (io.grpc.stub.StreamObserver)1 File (java.io.File)1 Derby (org.openlca.core.database.Derby)1 IDatabase (org.openlca.core.database.IDatabase)1 UpdateMode (org.openlca.jsonld.input.UpdateMode)1 ProtoRef (org.openlca.proto.ProtoRef)1 DataUpdateServiceGrpc (org.openlca.proto.grpc.DataUpdateServiceGrpc)1 DeleteRequest (org.openlca.proto.grpc.DeleteRequest)1 ProtoDataSet (org.openlca.proto.grpc.ProtoDataSet)1 ImportStatus (org.openlca.proto.io.input.ImportStatus)1 Refs (org.openlca.proto.io.output.Refs)1 Strings (org.openlca.util.Strings)1