Skip to content

Commit

Permalink
Merge branch 'staging' into OCD-2037
Browse files Browse the repository at this point in the history
  • Loading branch information
tmy1313 committed Jan 7, 2025
2 parents 3e26cf0 + bf0c8a6 commit 198298b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 423 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ public List<ActivityMetadata> metadataForProductById(@PathVariable("id") final L
})
@RequestMapping(value = "/metadata/versions", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/versions", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForVersions(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -354,7 +353,6 @@ public ActivityMetadataPage metadataForVersions(@RequestParam(required = false)
})
@RequestMapping(value = "/metadata/versions/{id:^-?\\d+$}", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/versions/{id}", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForVersionById(@PathVariable("id") final Long id,
@RequestParam(required = false) final Long start, @RequestParam(required = false) final Long end)
throws JsonParseException, IOException, EntityRetrievalException, ValidationException {
Expand Down Expand Up @@ -390,7 +388,6 @@ public List<ActivityMetadata> metadataForVersionById(@PathVariable("id") final L
})
@RequestMapping(value = "/metadata/acbs", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/acbs", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForAcbs(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -405,7 +402,6 @@ public ActivityMetadataPage metadataForAcbs(@RequestParam(required = false) Long
})
@RequestMapping(value = "/metadata/acbs/{id:^-?\\d+$}", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/acbs/{id}", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForAcbById(@PathVariable("id") final Long id,
@RequestParam(required = false) final Long start, @RequestParam(required = false) final Long end)
throws JsonParseException, IOException, EntityRetrievalException, ValidationException {
Expand Down Expand Up @@ -438,7 +434,6 @@ public List<ActivityMetadata> metadataForAcbById(@PathVariable("id") final Long
})
@RequestMapping(value = "/metadata/atls", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/atls", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForAtls(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -453,7 +448,6 @@ public ActivityMetadataPage metadataForAtls(@RequestParam(required = false) Long
})
@RequestMapping(value = "/metadata/atls/{id:^-?\\d+$}", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/atls/{id}", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForAtlById(@PathVariable("id") final Long id,
@RequestParam(required = false) final Long start, @RequestParam(required = false) final Long end)
throws JsonParseException, IOException, EntityRetrievalException, ValidationException {
Expand Down Expand Up @@ -485,7 +479,6 @@ public List<ActivityMetadata> metadataForAtlById(@PathVariable("id") final Long
@SecurityRequirement(name = SwaggerSecurityRequirement.BEARER)
})
@RequestMapping(value = "/metadata/users", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/users", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForUsers(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -504,7 +497,6 @@ public ActivityMetadataPage metadataForUsers(@RequestParam(required = false) Lon
})
@RequestMapping(value = "/metadata/announcements", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/announcements", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForAnnouncements(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -520,7 +512,6 @@ public ActivityMetadataPage metadataForAnnouncements(@RequestParam(required = fa
@SecurityRequirement(name = SwaggerSecurityRequirement.BEARER)
})
@RequestMapping(value = "/metadata/complaints", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/complaints", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForComplaints(@RequestParam final Long start,
@RequestParam final Long end) throws JsonParseException, IOException, ValidationException {
Date startDate = new Date(start);
Expand All @@ -538,7 +529,6 @@ public List<ActivityMetadata> metadataForComplaints(@RequestParam final Long sta
@SecurityRequirement(name = SwaggerSecurityRequirement.BEARER)
})
@RequestMapping(value = "/metadata/quarterly-reports", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/quarterly-reports", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForQuarterlyReports(@RequestParam final Long start,
@RequestParam final Long end) throws JsonParseException, IOException, ValidationException {

Expand Down Expand Up @@ -566,7 +556,6 @@ public List<ActivityMetadata> metadataForQuarterlyReports(@RequestParam final Lo
@SecurityRequirement(name = SwaggerSecurityRequirement.BEARER)
})
@RequestMapping(value = "/metadata/annual-reports", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/annual-reports", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForAnnualReports(@RequestParam final Long start,
@RequestParam final Long end) throws JsonParseException, IOException, ValidationException {
Date startDate = new Date(start);
Expand All @@ -583,7 +572,6 @@ public List<ActivityMetadata> metadataForAnnualReports(@RequestParam final Long
@SecurityRequirement(name = SwaggerSecurityRequirement.API_KEY)
})
@RequestMapping(value = "/metadata/corrective-action-plans", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/corrective-action-plans", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForCorrectiveActionPlans(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -601,7 +589,6 @@ public ActivityMetadataPage metadataForCorrectiveActionPlans(@RequestParam(requi
})
@RequestMapping(value = "/metadata/pending-surveillances", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/pending-surveillances", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForPendingSurveillances(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -618,7 +605,6 @@ public ActivityMetadataPage metadataForPendingSurveillances(@RequestParam(requir
})
@RequestMapping(value = "/metadata/change-requests", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/change-requests", responseClass = ActivityMetadata.class)
public List<ActivityMetadata> metadataForChangeRequests(@RequestParam final Long start,
@RequestParam final Long end) throws JsonParseException, IOException, ValidationException {
Date startDate = new Date(start);
Expand All @@ -637,7 +623,6 @@ public List<ActivityMetadata> metadataForChangeRequests(@RequestParam final Long
})
@RequestMapping(value = "/metadata/api-keys", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/api-keys", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForApiKeys(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -654,7 +639,6 @@ public ActivityMetadataPage metadataForApiKeys(@RequestParam(required = false) L
})
@RequestMapping(value = "/metadata/functionalities-tested", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/functionalities-tested", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForFunctionalitiesTested(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -671,7 +655,6 @@ public ActivityMetadataPage metadataForFunctionalitiesTested(@RequestParam(requi
})
@RequestMapping(value = "/metadata/standards", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/standards", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForStandards(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand All @@ -688,7 +671,6 @@ public ActivityMetadataPage metadataForStandards(@RequestParam(required = false)
})
@RequestMapping(value = "/metadata/svaps", method = RequestMethod.GET,
produces = "application/json; charset=utf-8")
@DeprecatedApiResponseFields(friendlyUrl = "/activity/metadata/svaps", responseClass = ActivityMetadataPage.class)
public ActivityMetadataPage metadataForSvaps(@RequestParam(required = false) Long start,
@RequestParam(required = false) Long end, @RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize) throws JsonParseException, IOException, ValidationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected void addConceptSpecificMetadata(ActivityDTO dto, ActivityMetadata meta
protected void addGenericMetadata(ActivityDTO dto, ActivityMetadata metadata) {
metadata.setId(dto.getId());
metadata.setDate(dto.getActivityDate());
metadata.setObjectId(dto.getActivityObjectId());
metadata.setObject(ActivityObject.builder()
.id(dto.getActivityObjectId())
.build());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package gov.healthit.chpl.activity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;

import gov.healthit.chpl.dao.DeveloperDAO;
import gov.healthit.chpl.domain.Developer;
import gov.healthit.chpl.domain.activity.ActivityCategory;
import gov.healthit.chpl.domain.activity.ActivityMetadata;
Expand All @@ -18,127 +15,32 @@
@Log4j2
@Component("developerActivityMetadataBuilder")
public class DeveloperActivityMetadataBuilder extends ActivityMetadataBuilder {
private ObjectMapper jsonMapper;

private DeveloperDAO developerDao;

@Autowired
public DeveloperActivityMetadataBuilder(ChplUserToCognitoUserUtil chplUserToCognitoUserUtil) {
public DeveloperActivityMetadataBuilder(ChplUserToCognitoUserUtil chplUserToCognitoUserUtil,
DeveloperDAO developerDao) {
super(chplUserToCognitoUserUtil);
jsonMapper = new ObjectMapper();
this.developerDao = developerDao;
}

@Override
protected void addConceptSpecificMetadata(final ActivityDTO activity, final ActivityMetadata metadata) {
if (!(metadata instanceof DeveloperActivityMetadata)) {
return;
}
DeveloperActivityMetadata developerMetadata = (DeveloperActivityMetadata) metadata;

//parse developer specific metadata
//for merges, the original data is a list of developers.
//for other developer activities it's just a single developer.
Developer origDeveloper = null;
List<Developer> origDevelopers = null;
if (activity.getOriginalData() != null) {
try {
origDeveloper =
jsonMapper.readValue(activity.getOriginalData(), Developer.class);
} catch (final Exception ignore) {
}

//if we couldn't parse it as a Developer
//try to parse it as a List.
if (origDeveloper == null) {
try {
origDevelopers = jsonMapper.readValue(activity.getOriginalData(),
jsonMapper.getTypeFactory().constructCollectionType(List.class, Developer.class));
} catch (final Exception ignore) {
}
}

//if the orig data is not a developer or a list, log an error
if (origDeveloper == null && origDevelopers == null) {
LOGGER.error("Could not parse activity ID " + activity.getId() + " original data as "
+ "a Developer or List<Developer>. JSON was: " + activity.getOriginalData());
}
}

Developer newDeveloper = null;
List<Developer> newDevelopers = null;
if (activity.getNewData() != null) {
try {
newDeveloper =
jsonMapper.readValue(activity.getNewData(), Developer.class);
} catch (final Exception ignore) {
}

//if we couldn't parse it as a Developer
//try to parse it as a List.
if (newDeveloper == null) {
try {
newDevelopers = jsonMapper.readValue(activity.getNewData(),
jsonMapper.getTypeFactory().constructCollectionType(List.class, Developer.class));
} catch (final Exception ignore) {
}
}

//if the new data is not a developer or a list, log an error
if (newDeveloper == null && newDevelopers == null) {
LOGGER.error("Could not parse activity ID " + activity.getId() + " new data as "
+ "a Developer or List<Developer>. JSON was: " + activity.getNewData());
}
}

if (newDeveloper != null && origDeveloper != null
&& newDevelopers == null && origDevelopers == null) {
//if there is a single new developer and single original developer
//that means the activity was editing the developer
parseDeveloperMetadata(developerMetadata, newDeveloper);
} else if (origDeveloper != null && newDeveloper == null
&& newDevelopers == null && origDevelopers == null) {
//if there is an original developer but no new developer
//then the developer was deleted - pull its info from the orig object
parseDeveloperMetadata(developerMetadata, origDeveloper);
} else if (newDeveloper != null && origDeveloper == null
&& newDevelopers == null && origDevelopers == null) {
//if there is a new developer but no original developer
//then the developer was just created
parseDeveloperMetadata(developerMetadata, newDeveloper);
} else if (newDevelopers != null && origDeveloper != null
&& newDeveloper == null && origDevelopers == null) {
//multiple new developers and a single original developer
//means the activity was a split
parseDeveloperMetadata(developerMetadata, activity, newDevelopers);
} else if (origDevelopers != null && newDeveloper != null
&& origDeveloper == null && newDevelopers == null) {
//multiple original developers and a single new developer
//means the activity was a merge
parseDeveloperMetadata(developerMetadata, newDeveloper);
}

DeveloperActivityMetadata developerMetadata = (DeveloperActivityMetadata) metadata;
developerMetadata.getCategories().add(ActivityCategory.DEVELOPER);
}

private void parseDeveloperMetadata(DeveloperActivityMetadata developerMetadata, Developer developer) {
developerMetadata.setDeveloperName(developer.getName());
developerMetadata.getObject().setName(developer.getName());
developerMetadata.setDeveloperCode(developer.getDeveloperCode());
}

/**
* Find the developer in the list that matches the id of the developer
* the activity was recorded for. Parse activity metadata from that developer.
* @param developerMetadata
* @param activity
* @param developers
*/
private void parseDeveloperMetadata(
DeveloperActivityMetadata developerMetadata, ActivityDTO activity,
List<Developer> developers) {
Long idToFind = activity.getActivityObjectId();
for (Developer currDev : developers) {
if (currDev != null && currDev.getId().equals(idToFind)) {
parseDeveloperMetadata(developerMetadata, currDev);
break;
if (metadata.getObject() != null && metadata.getObject().getId() != null) {
Developer dev = null;
try {
dev = developerDao.getById(metadata.getObject().getId(), true);
metadata.getObject().setName(dev.getName());
} catch (Exception ex) {
LOGGER.error("Could not find developer " + metadata.getObject().getId() + " for activity metadata.", ex);
}
}
}
Expand Down
Loading

0 comments on commit 198298b

Please sign in to comment.