Skip to content

Commit

Permalink
Merge pull request #49 from udsm-dhis2-lab/develop
Browse files Browse the repository at this point in the history
Merge APIs improvements data templates, import/export, datastore and mediators
  • Loading branch information
josephatJ authored Jun 7, 2024
2 parents 266aa0d + c06cd92 commit 98792af
Show file tree
Hide file tree
Showing 24 changed files with 1,402 additions and 124 deletions.
14 changes: 8 additions & 6 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<version>2.6.9</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>com.Adapter</groupId>
<artifactId>icare</artifactId>
<version>0.0.1-SNAPSHOT</version>
Expand Down Expand Up @@ -114,12 +115,6 @@
<artifactId>pact-jvm-provider-junit_2.10</artifactId>
<version>2.4.20</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
Expand All @@ -130,6 +125,13 @@
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.Adapter.icare.Controllers;


import com.Adapter.icare.Domains.Datastore;
import com.Adapter.icare.Services.DatastoreService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/datastore")
public class DatastoreController {

private final DatastoreService datastoreService;

public DatastoreController(DatastoreService datastoreService) {
this.datastoreService = datastoreService;
}

@GetMapping()
public List<Datastore> getDatastoreList() throws Exception {
return datastoreService.getDatastore();
}

@GetMapping("{uuid}")
public Datastore getDatastoreByUuid(@PathVariable("uuid") String uuid) throws Exception {
return datastoreService.getDatastoreByUuid(uuid);
}

@PostMapping()
public Datastore saveDatastore(@RequestBody Datastore datastore) throws Exception {
return datastoreService.saveDatastore(datastore);
}

@PutMapping("{uuid}")
public Datastore updateDatastore(@PathVariable("uuid") String uuid, @RequestBody Datastore datastore) throws Exception {
if (datastore.getUuid() == null) {
datastore.setUuid(uuid);
}
return datastoreService.updateDatastore(datastore);
}

@DeleteMapping("{uuid}")
public void deleteDatastore(@PathVariable("uuid") String uuid) throws Exception {
datastoreService.deleteDatastore(uuid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.Adapter.icare.Controllers;


import com.Adapter.icare.Domains.Datastore;
import com.Adapter.icare.Domains.Mediator;
import com.Adapter.icare.Services.DatastoreService;
import com.Adapter.icare.Services.MediatorsService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/")
public class MediatorsController {

private final MediatorsService mediatorsService;
private final DatastoreService datastoreService;

public MediatorsController(MediatorsService mediatorsService, DatastoreService datastoreService) {
this.mediatorsService = mediatorsService;
this.datastoreService = datastoreService;
}

@PostMapping("mediators")
public Mediator saveMediator(@RequestBody Mediator mediator) throws Exception {
return mediatorsService.saveMediatorConfigs(mediator);
}

@PutMapping("mediators/{uuid}")
public Mediator updateMediator(@PathVariable("uuid") String uuid, @RequestBody Mediator mediator) throws Exception {
if (mediator.getUuid() == null) {
mediator.setUuid(uuid);
}
return mediatorsService.updateMediator(mediator);
}

@DeleteMapping("mediators/{uuid}")
public void deleteMediator(@PathVariable("uuid") String uuid) throws Exception {
mediatorsService.deleteMediator(uuid);
}

@GetMapping("dataTemplates")
public List<Map<String, Object>> getDataTemplatesList () throws Exception {
List<Datastore> dataTemplateNameSpaceDetails = datastoreService.getDatastoreNamespaceDetails("dataTemplates");
List<Map<String, Object>> dataTemplates = new ArrayList<>();
for(Datastore datastore: dataTemplateNameSpaceDetails) {
Map<String, Object> dataTemplate = datastore.getValue();
dataTemplate.put("uuid", datastore.getUuid());
dataTemplates.add(dataTemplate);
}
return dataTemplates;
}

@GetMapping("dataTemplates/{id}")
public Map<String, Object> getDataTemplateById(@PathVariable("id") String id) throws Exception {
Datastore datastore = datastoreService.getDatastoreByUuid(id);
if (datastore == null) {
throw new Exception("Data template for the id " + id + " does not exists");
}
return datastore.getValue();
}

@PostMapping(value = "dataTemplates", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String passDataToMediator(@RequestBody Map<String, Object> data) throws Exception {
/**
* Send data to Mediator where all the logics will be done.
*/

return mediatorsService.sendDataToMediator(data);
}
}
Loading

0 comments on commit 98792af

Please sign in to comment.