Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 380] Data and analytic view container type #381

Merged
7 commits merged into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change as these resource links are defined by available export views for display views. As these augments all individual responses I prefer the values be static and bound to the persisted entities. Which will require a bit of design to afford dynamism.

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
Loading