package no.uio.ifi.trackfind.backend.services;

import no.uio.ifi.trackfind.backend.dao.Dataset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Collection;
import java.util.function.Function;

/**
 * Service for querying remote GSuite service for performing JSON to GSuite conversion.
 */
@Service
public class GSuiteService implements Function<Collection<Dataset>, String> {

    private RestTemplate restTemplate;

    /**
     * Convert datasets to GSuite.
     *
     * @param datasets Datasets to convert.
     * @return GSuite string.
     */
    @SuppressWarnings("unchecked")
    @Override
    public String apply(Collection<Dataset> datasets) {
        HttpEntity<Collection<Dataset>> request = new HttpEntity<>(datasets);
        return restTemplate.postForObject("http://gsuite/togsuite", request, String.class);
    }

    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

}

@@ -326,16 +326,64 @@
 ection;%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A
 import j
@@ -410,16 +410,16 @@
 nction;%0A
-
 %0A/**%0A * 
@@ -633,16 +633,57 @@
 emplate;
+%0A    private SchemaService schemaService;
 %0A%0A    /*
@@ -925,36 +925,191 @@
     
-HttpEntity%3CCollection%3CDatase
+Map%3CString, Object%3E body = new HashMap%3C%3E();%0A        body.put(%22attributes%22, schemaService.getAttributes());%0A        body.put(%22datasets%22, datasets);%0A        HttpEntity%3CMap%3CString, Objec
 t%3E%3E 
@@ -1135,24 +1135,20 @@
 ntity%3C%3E(
-datasets
+body
 );%0A     
@@ -1313,24 +1313,24 @@
 Template) %7B%0A
-
         this
@@ -1366,10 +1366,140 @@
 %0A    %7D%0A%0A
+    @Autowired%0A    public void setSchemaService(SchemaService schemaService) %7B%0A        this.schemaService = schemaService;%0A    %7D%0A%0A
 %7D%0A

Send FAIR attributes to GSuite service.