-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from udsm-dhis2-lab/develop
Merge APIs improvements data templates, import/export, datastore and mediators
- Loading branch information
Showing
24 changed files
with
1,402 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
backend/src/main/java/com/Adapter/icare/Controllers/DatastoreController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
backend/src/main/java/com/Adapter/icare/Controllers/MediatorsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.