All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.doip.sbyterepo.JsonDO Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package org.bdware.doip.sbyterepo;

import com.google.gson.JsonObject;
import org.bdware.doip.codec.digitalObject.DigitalObject;
import org.bdware.doip.codec.digitalObject.DoType;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
import org.bdware.doip.codec.operations.BasicOperations;

import java.nio.charset.StandardCharsets;

public class JsonDO extends DigitalObject {
    static DoipMessageFactory factory = new DoipMessageFactory();

    public JsonDO(String id, DoType type) {
        super(id, type);
    }


    public static JsonDO createDO(byte[] data) {
        JsonDO digitalObject = new JsonDO(null, DoType.DO);
        
        return digitalObject;
    }

    public static JsonDO updateDO(String doid, String url, String method, JsonObject headers) {
        JsonDO digitalObject = new JsonDO(doid, DoType.DO);
        digitalObject.addAttribute("url", url);
        digitalObject.addAttribute("method", method);
        digitalObject.attributes.add("headers", headers);
        return digitalObject;
    }

    public static DoipMessage retrieveMsg(String doid, String query, JsonObject headers, byte[] body) {
        DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
        builder.createRequest(doid, BasicOperations.Retrieve.getName());
        builder.addAttributes("query", query);
        builder.addAttributes("headers", headers);
        builder.setBody(body);
        return builder.create();
    }

    public static DoipMessage helloMsg(String doid) {
        DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
        builder.createRequest(doid, BasicOperations.Hello.getName());
        return builder.create();
    }
    //delete is not supported
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy