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

com.fivefaces.cloud.workflow.function.UpdateStructure Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fivefaces.cloud.workflow.function;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fivefaces.common.util.JsonUtils;
import org.json.JSONObject;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;

public class UpdateStructure extends Function{

    public static final String FUNCTION_NAME = "UPDATE_STRUCTURE";

    public UpdateStructure(RestTemplateBuilder restTemplateBuilder) {
        super(restTemplateBuilder);
    }

    @Override
    public void setup(JSONObject jsonObject) {
    }

    @Override
    public JSONObject process(JSONObject jsonParameters) throws JsonProcessingException {
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8081/api/v1/structure/updateFromWorkflow");
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        MultiValueMap requestMap = new LinkedMultiValueMap<>();

        JSONObject inputJson = (JSONObject) jsonParameters.get("update");
        requestMap.add("queryJSON", new JsonUtils().marshall(inputJson.toString()));
        HttpEntity> request = new HttpEntity<>(requestMap, headers);
        restTemplateBuilder.build().postForEntity( builder.build().encode().toUri(), request , String.class );
        return new JSONObject("{}");
    }

    @Override
    public void cleanup(JSONObject jsonObject) {

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy