-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avniproject/avni-product#1576 | GET /api/approvalStatuses
- Loading branch information
Showing
6 changed files
with
261 additions
and
6 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
34 changes: 34 additions & 0 deletions
34
avni-server-api/src/main/java/org/avni/server/dao/EntityApprovalStatusSearchParams.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,34 @@ | ||
package org.avni.server.dao; | ||
|
||
import org.joda.time.DateTime; | ||
|
||
|
||
public class EntityApprovalStatusSearchParams { | ||
private final DateTime lastModifiedDateTime; | ||
private final DateTime now; | ||
private final String entityType; | ||
private final String entityTypeUuid; | ||
|
||
public EntityApprovalStatusSearchParams(DateTime lastModifiedDateTime, DateTime now, String entityType, String entityTypeUuid) { | ||
this.lastModifiedDateTime = lastModifiedDateTime; | ||
this.now = now; | ||
this.entityType = entityType; | ||
this.entityTypeUuid = entityTypeUuid; | ||
} | ||
|
||
public DateTime getLastModifiedDateTime() { | ||
return lastModifiedDateTime; | ||
} | ||
|
||
public DateTime getNow() { | ||
return now; | ||
} | ||
|
||
public String getEntityType() { | ||
return entityType; | ||
} | ||
|
||
public String getEntityTypeUuid() { | ||
return entityTypeUuid; | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
avni-server-api/src/main/java/org/avni/server/web/api/EntityApprovalStatusApiController.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,51 @@ | ||
package org.avni.server.web.api; | ||
|
||
import org.avni.server.dao.EntityApprovalStatusRepository; | ||
import org.avni.server.dao.EntityApprovalStatusSearchParams; | ||
import org.avni.server.domain.EntityApprovalStatus; | ||
import org.avni.server.service.EntityApprovalStatusService; | ||
import org.avni.server.service.accessControl.AccessControlService; | ||
import org.avni.server.web.response.EntityApprovalStatusResponse; | ||
import org.avni.server.web.response.ResponsePage; | ||
import org.joda.time.DateTime; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.ArrayList; | ||
|
||
@RestController | ||
public class EntityApprovalStatusApiController { | ||
|
||
private final EntityApprovalStatusRepository entityApprovalStatusRepository; | ||
private final EntityApprovalStatusService entityApprovalStatusService; | ||
private final AccessControlService accessControlService; | ||
|
||
@Autowired | ||
public EntityApprovalStatusApiController(EntityApprovalStatusRepository entityApprovalStatusRepository, EntityApprovalStatusService entityApprovalStatusService, AccessControlService accessControlService) { | ||
this.entityApprovalStatusRepository = entityApprovalStatusRepository; | ||
this.entityApprovalStatusService = entityApprovalStatusService; | ||
this.accessControlService = accessControlService; | ||
} | ||
|
||
@RequestMapping(value = "/api/approvalStatuses", method = RequestMethod.GET) | ||
@PreAuthorize(value = "hasAnyAuthority('user')") | ||
public ResponsePage getEntityApprovalStatuses(@RequestParam(value = "lastModifiedDateTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, | ||
@RequestParam(value = "now", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, | ||
@RequestParam(value = "entityType", required = false) String entityType, | ||
@RequestParam(value = "entityTypeId", required = false) String entityTypeUuid, | ||
Pageable pageable) { | ||
|
||
Page<EntityApprovalStatus> entityApprovalStatuses = entityApprovalStatusRepository.findEntityApprovalStatuses(new EntityApprovalStatusSearchParams(lastModifiedDateTime, now, entityType, entityTypeUuid), pageable); | ||
ArrayList<EntityApprovalStatusResponse> entityApprovalStatusResponse = new ArrayList<>(); | ||
entityApprovalStatuses.forEach(entityApprovalStatus -> entityApprovalStatusResponse.add(EntityApprovalStatusResponse.fromEntityApprovalStatus(entityApprovalStatus, entityApprovalStatusService.getEntityUuid(entityApprovalStatus)))); | ||
accessControlService.checkApprovePrivilegeOnEntityApprovalStatuses(entityApprovalStatuses.getContent()); | ||
return new ResponsePage(entityApprovalStatusResponse, entityApprovalStatuses.getNumberOfElements(), entityApprovalStatuses.getTotalPages(), entityApprovalStatuses.getSize()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
avni-server-api/src/main/java/org/avni/server/web/response/EntityApprovalStatusResponse.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,20 @@ | ||
package org.avni.server.web.response; | ||
|
||
import org.avni.server.domain.EntityApprovalStatus; | ||
|
||
import java.util.LinkedHashMap; | ||
|
||
public class EntityApprovalStatusResponse extends LinkedHashMap<String, Object> { | ||
public static EntityApprovalStatusResponse fromEntityApprovalStatus(EntityApprovalStatus entityApprovalStatus, String entityUuid) { | ||
EntityApprovalStatusResponse entityApprovalStatusResponse = new EntityApprovalStatusResponse(); | ||
entityApprovalStatusResponse.put("Entity ID", entityUuid); | ||
entityApprovalStatusResponse.put("Entity type", entityApprovalStatus.getEntityType()); | ||
entityApprovalStatusResponse.put("Entity type ID", entityApprovalStatus.getEntityTypeUuid()); | ||
entityApprovalStatusResponse.put("Approval status", entityApprovalStatus.getApprovalStatus().getStatus()); | ||
entityApprovalStatusResponse.put("Approval status comment", entityApprovalStatus.getApprovalStatusComment()); | ||
entityApprovalStatusResponse.put("Status date time", entityApprovalStatus.getStatusDateTime()); | ||
|
||
Response.putAudit(entityApprovalStatus, entityApprovalStatusResponse); | ||
return entityApprovalStatusResponse; | ||
} | ||
} |
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