Skip to content

Commit

Permalink
[Issue 380] Data and analytic view container type (#381)
Browse files Browse the repository at this point in the history
* Add container type to data and analytics view

* Update individual model resources

* Update tests

* Add eof newline to data and analytics default yaml

* Update export view names

* Fix analytics endpoint mapping for academicAge

* Remove authorize for now
  • Loading branch information
wwelling authored Aug 15, 2023
1 parent b9da1b7 commit 135c275
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.scholars.middleware.discovery.argument.DiscoveryQuantityDistributionDescriptor;
import edu.tamu.scholars.middleware.discovery.argument.DiscoveryAcademicAgeDescriptor;
import edu.tamu.scholars.middleware.discovery.argument.DiscoveryQuantityDistributionDescriptor;
import edu.tamu.scholars.middleware.discovery.argument.FilterArg;
import edu.tamu.scholars.middleware.discovery.argument.QueryArg;
import edu.tamu.scholars.middleware.discovery.model.repo.IndividualRepo;
import edu.tamu.scholars.middleware.discovery.response.DiscoveryQuantityDistribution;
import edu.tamu.scholars.middleware.discovery.response.DiscoveryAcademicAge;
import edu.tamu.scholars.middleware.discovery.response.DiscoveryQuantityDistribution;

@RestController
@RequestMapping("/individual/analytics")
Expand All @@ -25,8 +24,7 @@ public class IndividualAnalyticsController {
@Autowired
private IndividualRepo repo;

@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/aca")
@GetMapping("/academicAge")
public ResponseEntity<DiscoveryAcademicAge> academicAge(
QueryArg query,
List<FilterArg> filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import edu.tamu.scholars.middleware.discovery.assembler.model.IndividualModel;
import edu.tamu.scholars.middleware.discovery.model.Individual;
import edu.tamu.scholars.middleware.discovery.model.Organization;
import edu.tamu.scholars.middleware.discovery.model.Person;
import edu.tamu.scholars.middleware.discovery.model.repo.IndividualRepo;
import edu.tamu.scholars.middleware.export.exception.UnknownExporterTypeException;
import edu.tamu.scholars.middleware.export.service.Exporter;
Expand Down Expand Up @@ -54,16 +56,68 @@ public ResponseEntity<StreamingResponseBody> export(

@Override
public IndividualModel process(IndividualModel resource) {
Individual individual = resource.getContent();
if (individual != null) {
if (individual.getProxy().equals(Person.class.getSimpleName())) {
addResource(resource, new ResourceLink(individual, "docx", "Single Page Bio", "Individual single page bio export"));
addResource(resource, new ResourceLink(individual, "docx", "Profile Summary", "Individual profile summary export"));
addResource(resource, new ResourceLink(individual, "zip", "Last 5 Years", "Individual 5 year publications export"));
addResource(resource, new ResourceLink(individual, "zip", "Last 8 Years", "Individual 8 year publications export"));
} else if (individual.getProxy().equals(Organization.class.getSimpleName())) {
addResource(resource, new ResourceLink(individual, "zip", "Last 5 Years", "Organization 5 year publications export"));
addResource(resource, new ResourceLink(individual, "zip", "Last 8 Years", "Organization 8 year publications export"));
}
}

return resource;
}

private void addResource(IndividualModel resource, ResourceLink link) {
try {
resource.add(linkTo(methodOn(this.getClass()).export(
resource.getContent().getId(),
"docx",
"Profile Summary"
)).withRel("export").withTitle("Individual export"));
link.getIndividual().getId(),
link.getType(),
link.getName()
)).withRel(link.getName().toLowerCase().replace(" ", "_")).withTitle(link.getTitle()));
} catch (NullPointerException | UnknownExporterTypeException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return resource;
}

private class ResourceLink {
private final Individual individual;
private final String type;
private final String name;
private final String title;

private ResourceLink(
Individual individual,
String type,
String name,
String title
) {
this.individual = individual;
this.type = type;
this.name = name;
this.title = title;
}

public Individual getIndividual() {
return individual;
}

public String getType() {
return type;
}

public String getName() {
return name;
}

public String getTitle() {
return title;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package edu.tamu.scholars.middleware.view.model;

public enum ContainerType {
ACADEMIC_AGE_GROUP, QUANTITY_DISTRIBUTION, PROFILE_SUMMARIES_EXPORT
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package edu.tamu.scholars.middleware.view.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

@Entity
Expand All @@ -9,4 +12,16 @@ public class DataAndAnalyticsView extends CollectionView {

private static final long serialVersionUID = 2912876591264398726L;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private ContainerType type;

public ContainerType getType() {
return type;
}

public void setType(ContainerType type) {
this.type = type;
}

}
3 changes: 3 additions & 0 deletions src/main/resources/defaults/dataAndanalyticViews.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
- name: Publications by Academic Age Group
layout: CONTAINER
type: ACADEMIC_AGE_GROUP
- name: Research by UN SDG
layout: CONTAINER
type: QUANTITY_DISTRIBUTION
- name: Download Profile Summaries by Department
layout: CONTAINER
type: PROFILE_SUMMARIES_EXPORT
8 changes: 4 additions & 4 deletions src/main/resources/defaults/displayViews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
- field: class
value: Relationship AND type:Grant
opKey: EXPRESSION
- name: 5 Year Publications
- name: Last 5 Years
contentTemplate: "defaults/displayViews/persons/5YearPublicationsContentTemplate.html"
headerTemplate: "defaults/displayViews/emptyHeaderTemplate.html"
lazyReferences:
Expand Down Expand Up @@ -127,7 +127,7 @@
- field: class
value: Relationship AND type:Grant
opKey: EXPRESSION
- name: 8 Year Publications
- name: Last 8 Years
contentTemplate: "defaults/displayViews/persons/8YearPublicationsContentTemplate.html"
headerTemplate: "defaults/displayViews/emptyHeaderTemplate.html"
lazyReferences:
Expand Down Expand Up @@ -930,7 +930,7 @@
asideTemplate: "defaults/displayViews/organizations/asideTemplate.html"
asideLocation: RIGHT
exportViews:
- name: 5 Year Publications
- name: Last 5 Years
contentTemplate: "defaults/displayViews/persons/5YearPublicationsContentTemplate.html"
headerTemplate: "defaults/displayViews/emptyHeaderTemplate.html"
multipleReference:
Expand Down Expand Up @@ -987,7 +987,7 @@
- field: class
value: Relationship AND type:Grant
opKey: EXPRESSION
- name: 8 Year Publications
- name: Last 8 Years
contentTemplate: "defaults/displayViews/persons/8YearPublicationsContentTemplate.html"
headerTemplate: "defaults/displayViews/emptyHeaderTemplate.html"
multipleReference:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import edu.tamu.scholars.middleware.model.OpKey;
import edu.tamu.scholars.middleware.view.model.Boost;
import edu.tamu.scholars.middleware.view.model.ContainerType;
import edu.tamu.scholars.middleware.view.model.DataAndAnalyticsView;
import edu.tamu.scholars.middleware.view.model.DirectoryView;
import edu.tamu.scholars.middleware.view.model.DiscoveryView;
Expand Down Expand Up @@ -37,6 +38,7 @@ public static DataAndAnalyticsView getMockDataAndAnalyticsView() {

dataAndAnalyticsView.setName(MOCK_VIEW_NAME);
dataAndAnalyticsView.setLayout(Layout.GRID);
dataAndAnalyticsView.setType(ContainerType.PROFILE_SUMMARIES_EXPORT);

Map<String, String> templates = new HashMap<String, String>();
templates.put("default", "<h1>Element template from WSYWIG</h1>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testCreateDataAndAnalyticsView() throws JsonProcessingException, Exc
requestFields(
describeDataAndAnalyticsView.withField("name", "The name of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("layout", "The layout of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("type", "The container type of the Data And Analytics View."),
describeDataAndAnalyticsView.withSubsection("templates", "The result templates of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("styles", "An array of result style strings of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("fields", "An array of fields of the Data And Analytics View."),
Expand All @@ -67,6 +68,7 @@ public void testCreateDataAndAnalyticsView() throws JsonProcessingException, Exc
responseFields(
describeDataAndAnalyticsView.withField("name", "The name of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("layout", "The layout of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("type", "The container type of the Data And Analytics View."),
describeDataAndAnalyticsView.withSubsection("templates", "The result templates of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("styles", "An array of result style strings of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("fields", "An array of fields of the Data And Analytics View."),
Expand Down Expand Up @@ -98,6 +100,7 @@ public void testUpdateDataAndAnalyticsView() throws JsonProcessingException, Exc
describeDataAndAnalyticsView.withField("id", "The Data And Analytics View id."),
describeDataAndAnalyticsView.withField("name", "The name of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("layout", "The layout of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("type", "The container type of the Data And Analytics View."),
describeDataAndAnalyticsView.withSubsection("templates", "The result templates of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("styles", "An array of result style strings of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("fields", "An array of fields of the Data And Analytics View."),
Expand All @@ -114,6 +117,7 @@ public void testUpdateDataAndAnalyticsView() throws JsonProcessingException, Exc
responseFields(
describeDataAndAnalyticsView.withField("name", "The name of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("layout", "The layout of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("type", "The container type of the Data And Analytics View."),
describeDataAndAnalyticsView.withSubsection("templates", "The result templates of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("styles", "An array of result style strings of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("fields", "An array of fields of the Data And Analytics View."),
Expand Down Expand Up @@ -152,6 +156,7 @@ public void testPatchTheme() throws JsonProcessingException, Exception {
describeDataAndAnalyticsView.withParameter("id", "The Data And Analytics View id.").optional(),
describeDataAndAnalyticsView.withParameter("name", "The name of the Data And Analytics View.").optional(),
describeDataAndAnalyticsView.withParameter("layout", "The layout of the Data And Analytics View.").optional(),
describeDataAndAnalyticsView.withParameter("type", "The container type of the Data And Analytics View.").optional(),
describeDataAndAnalyticsView.withParameter("templates", "The result templates of the Data And Analytics View.").optional(),
describeDataAndAnalyticsView.withParameter("styles", "An array of result style strings of the Data And Analytics View.").optional(),
describeDataAndAnalyticsView.withParameter("fields", "An array of fields of the Data And Analytics View.").optional(),
Expand All @@ -168,6 +173,7 @@ public void testPatchTheme() throws JsonProcessingException, Exception {
responseFields(
describeDataAndAnalyticsView.withField("name", "The name of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("layout", "The layout of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("type", "The container type of the Data And Analytics View."),
describeDataAndAnalyticsView.withSubsection("templates", "The result templates of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("styles", "An array of result style strings of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("fields", "An array of fields of the Data And Analytics View."),
Expand Down Expand Up @@ -206,6 +212,7 @@ public void testGetDataAndAnalyticsView() throws JsonProcessingException, Except
responseFields(
describeDataAndAnalyticsView.withField("name", "The name of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("layout", "The layout of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("type", "The container type of the Data And Analytics View."),
describeDataAndAnalyticsView.withSubsection("templates", "The result templates of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("styles", "An array of result style strings of the Data And Analytics View."),
describeDataAndAnalyticsView.withField("fields", "An array of fields of the Data And Analytics View."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void testGettersAndSetters() {
assertEquals(1L, dataAndAnalyticsView.getId(), 1);
assertEquals(MOCK_VIEW_NAME, dataAndAnalyticsView.getName());
assertEquals(Layout.GRID, dataAndAnalyticsView.getLayout());
assertEquals(ContainerType.PROFILE_SUMMARIES_EXPORT, dataAndAnalyticsView.getType());

assertTrue(dataAndAnalyticsView.getTemplates().containsKey("default"));
assertEquals("<h1>Element template from WSYWIG</h1>", dataAndAnalyticsView.getTemplates().get("default"));
Expand Down

0 comments on commit 135c275

Please sign in to comment.