«
Previous
|
Next
»
Revision 63333
Added by Katerina Iatropoulou 18 days ago
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/helpers/csv/DatasourceCsv.java | ||
---|---|---|
8 | 8 |
@JsonPropertyOrder({ "name", "type", "compatibility", "oaipmh", "websiteUrl" }) |
9 | 9 |
public class DatasourceCsv implements CsvEntity { |
10 | 10 |
|
11 |
@JsonProperty("Νame")
|
|
11 |
@JsonProperty("Name")
|
|
12 | 12 |
String name; |
13 | 13 |
@JsonProperty("Type") |
14 | 14 |
String type; |
... | ... | |
58 | 58 |
public void setWebsiteUrl(String websiteUrl) { |
59 | 59 |
this.websiteUrl = websiteUrl; |
60 | 60 |
} |
61 |
} |
|
61 |
} |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/helpers/csv/ResearchProductCsv.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import com.fasterxml.jackson.annotation.JsonProperty; |
4 | 4 |
import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
5 |
import lombok.Data; |
|
6 |
|
|
7 | 5 |
import java.util.List; |
8 | 6 |
|
9 | 7 |
//Type Title Authors Publication Year DOI Type Peer Reviewed Diamond Journal Journal Download from Publicly Funded Funder|Project Name (GA Number) Access Green OA colour |
10 | 8 |
|
11 |
@Data |
|
12 | 9 |
@JsonPropertyOrder({"researchProduct", "title", "authors", "publicationYear", "doi", "type", "peerReviewed", |
13 | 10 |
"diamondJournal", "downloadFrom", "publiclyFunded", "funder_Project", "access", "green", "oaColour"}) |
14 | 11 |
public class ResearchProductCsv implements CsvEntity { |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/helpers/html/ResearchProductHtml.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.search.helpers.html; |
2 | 2 |
|
3 |
import lombok.Data; |
|
4 |
|
|
5 |
@Data |
|
6 | 3 |
public class ResearchProductHtml implements HtmlEntity { |
7 | 4 |
String type; |
8 | 5 |
String title; |
... | ... | |
14 | 11 |
String journal; |
15 | 12 |
String projectName_gaNumber; |
16 | 13 |
String accessMode; |
14 |
|
|
15 |
public String getType() { |
|
16 |
return type; |
|
17 |
} |
|
18 |
|
|
19 |
public void setType(String type) { |
|
20 |
this.type = type; |
|
21 |
} |
|
22 |
|
|
23 |
public String getTitle() { |
|
24 |
return title; |
|
25 |
} |
|
26 |
|
|
27 |
public void setTitle(String title) { |
|
28 |
this.title = title; |
|
29 |
} |
|
30 |
|
|
31 |
public String getAuthors() { |
|
32 |
return authors; |
|
33 |
} |
|
34 |
|
|
35 |
public void setAuthors(String authors) { |
|
36 |
this.authors = authors; |
|
37 |
} |
|
38 |
|
|
39 |
public String getPublicationYear() { |
|
40 |
return publicationYear; |
|
41 |
} |
|
42 |
|
|
43 |
public void setPublicationYear(String publicationYear) { |
|
44 |
this.publicationYear = publicationYear; |
|
45 |
} |
|
46 |
|
|
47 |
public String getDoi() { |
|
48 |
return doi; |
|
49 |
} |
|
50 |
|
|
51 |
public void setDoi(String doi) { |
|
52 |
this.doi = doi; |
|
53 |
} |
|
54 |
|
|
55 |
public String getPermanentIdentifier() { |
|
56 |
return permanentIdentifier; |
|
57 |
} |
|
58 |
|
|
59 |
public void setPermanentIdentifier(String permanentIdentifier) { |
|
60 |
this.permanentIdentifier = permanentIdentifier; |
|
61 |
} |
|
62 |
|
|
63 |
public String getPublicationType() { |
|
64 |
return publicationType; |
|
65 |
} |
|
66 |
|
|
67 |
public void setPublicationType(String publicationType) { |
|
68 |
this.publicationType = publicationType; |
|
69 |
} |
|
70 |
|
|
71 |
public String getJournal() { |
|
72 |
return journal; |
|
73 |
} |
|
74 |
|
|
75 |
public void setJournal(String journal) { |
|
76 |
this.journal = journal; |
|
77 |
} |
|
78 |
|
|
79 |
public String getProjectName_gaNumber() { |
|
80 |
return projectName_gaNumber; |
|
81 |
} |
|
82 |
|
|
83 |
public void setProjectName_gaNumber(String projectName_gaNumber) { |
|
84 |
this.projectName_gaNumber = projectName_gaNumber; |
|
85 |
} |
|
86 |
|
|
87 |
public String getAccessMode() { |
|
88 |
return accessMode; |
|
89 |
} |
|
90 |
|
|
91 |
public void setAccessMode(String accessMode) { |
|
92 |
this.accessMode = accessMode; |
|
93 |
} |
|
17 | 94 |
} |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/mappers/csv/OrganizationCsvMapper.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.search.mappers.csv; |
2 | 2 |
|
3 | 3 |
import eu.dnetlib.data.search.helpers.csv.OrganizationCsv; |
4 |
import eu.dnetlib.dhp.schema.solr.Organization; |
|
4 | 5 |
import eu.dnetlib.dhp.schema.solr.SolrRecord; |
5 | 6 |
import org.mapstruct.Mapper; |
6 | 7 |
import org.mapstruct.Mapping; |
... | ... | |
8 | 9 |
@Mapper(componentModel = "spring") |
9 | 10 |
public interface OrganizationCsvMapper { |
10 | 11 |
|
11 |
@Mapping(target="name", source = "organization.legalname")
|
|
12 |
@Mapping(target="name", expression = "java(extractOrganizationName(solrRecord))")
|
|
12 | 13 |
@Mapping(target="country", source="organization.country.label") |
13 | 14 |
OrganizationCsv toOrganizationCsv(SolrRecord solrRecord); |
15 |
|
|
16 |
default String extractOrganizationName(SolrRecord solrRecord) { |
|
17 |
if (solrRecord == null || solrRecord.getOrganization() == null) { |
|
18 |
return ""; |
|
19 |
} |
|
20 |
|
|
21 |
StringBuilder organizationName = new StringBuilder(); |
|
22 |
Organization organization = solrRecord.getOrganization(); |
|
23 |
|
|
24 |
if (organization.getLegalname() != null) { |
|
25 |
organizationName.append(organization.getLegalname()); |
|
26 |
if (organization.getLegalshortname() != null) { |
|
27 |
organizationName.append(" (").append(organization.getLegalshortname()).append(")"); |
|
28 |
} |
|
29 |
} else if (organization.getLegalshortname() != null) { |
|
30 |
organizationName.append(organization.getLegalshortname()); |
|
31 |
} |
|
32 |
|
|
33 |
return organizationName.toString(); |
|
34 |
} |
|
35 |
|
|
14 | 36 |
} |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/mappers/csv/ResearchProductCsvMapper.java | ||
---|---|---|
20 | 20 |
@Mapping(target="researchProduct", source = "result.resulttype") |
21 | 21 |
@Mapping(target="title", source="result.maintitle") |
22 | 22 |
@Mapping(target="authors", expression = "java(extractAuthor(solrRecord))") |
23 |
@Mapping(target = "publicationYear", source = "result.publicationdate") |
|
23 |
@Mapping(target = "publicationYear", source = "result.publicationdate", defaultValue = "")
|
|
24 | 24 |
@Mapping(target = "doi", expression = "java(extractDoi(solrRecord))") |
25 | 25 |
@Mapping(target = "type", source = "result.resulttype") |
26 | 26 |
@Mapping(target = "peerReviewed", expression = "java(extractPeerReviewed(solrRecord))") |
27 |
@Mapping(target = "diamondJournal", source = "result.inDiamondJournal") |
|
28 |
@Mapping(target = "journal", source = "result.journal.name") |
|
27 |
@Mapping(target = "diamondJournal", source = "result.isInDiamondJournal")
|
|
28 |
@Mapping(target = "journal", source = "result.journal.name", defaultValue = "")
|
|
29 | 29 |
@Mapping(target = "downloadFrom", expression = "java(extractDownloadFrom(solrRecord))") |
30 | 30 |
@Mapping(target = "publiclyFunded", source = "result.publiclyFunded") |
31 | 31 |
@Mapping(target = "funder_Project", expression = "java(extractFunder(solrRecord))") |
32 | 32 |
@Mapping(target = "access", source = "result.bestaccessright.label") |
33 |
@Mapping(target = "green", source = "result.green")
|
|
33 |
@Mapping(target = "green", source = "result.isGreen")
|
|
34 | 34 |
@Mapping(target = "oaColour", source = "result.openAccessColor") |
35 | 35 |
ResearchProductCsv toResearchProductCsv(SolrRecord solrRecord); |
36 | 36 |
|
37 | 37 |
@Mapping(target="researchProduct", source = "result.resulttype") |
38 | 38 |
@Mapping(target="title", source="result.maintitle") |
39 | 39 |
@Mapping(target="authors", expression = "java(extractAuthor(solrRecord))") |
40 |
@Mapping(target = "publicationYear", source = "result.publicationdate") |
|
40 |
@Mapping(target = "publicationYear", source = "result.publicationdate", defaultValue = "")
|
|
41 | 41 |
@Mapping(target = "doi", expression = "java(extractDoi(solrRecord))") |
42 | 42 |
@Mapping(target = "type", source = "result.resulttype") |
43 | 43 |
@Mapping(target = "peerReviewed", expression = "java(extractPeerReviewed(solrRecord))") |
44 |
@Mapping(target = "diamondJournal", source = "result.inDiamondJournal") |
|
45 |
@Mapping(target = "journal", source = "result.journal.name") |
|
44 |
@Mapping(target = "diamondJournal", source = "result.isInDiamondJournal")
|
|
45 |
@Mapping(target = "journal", source = "result.journal.name", defaultValue = "")
|
|
46 | 46 |
@Mapping(target = "downloadFrom", expression = "java(extractDownloadFrom(solrRecord))") |
47 | 47 |
@Mapping(target = "publiclyFunded", source = "result.publiclyFunded") |
48 | 48 |
@Mapping(target = "access", source = "result.bestaccessright.label") |
49 |
@Mapping(target = "green", source = "result.green")
|
|
49 |
@Mapping(target = "green", source = "result.isGreen")
|
|
50 | 50 |
@Mapping(target = "oaColour", source = "result.openAccessColor") |
51 | 51 |
ResearchProductCsv toSimpleResearchProductCsv(SolrRecord solrRecord); |
52 | 52 |
|
... | ... | |
92 | 92 |
return Optional.ofNullable(solrRecord.getPid()) |
93 | 93 |
.map(List::stream) |
94 | 94 |
.orElseGet(Stream::empty) |
95 |
.filter(pid -> "doi".equalsIgnoreCase(pid.getType())) |
|
95 |
.filter(pid -> "doi".equalsIgnoreCase(pid.getTypeCode()))
|
|
96 | 96 |
.map(Pid::getValue) |
97 | 97 |
.collect(Collectors.toList()); |
98 | 98 |
} |
... | ... | |
111 | 111 |
return Optional.ofNullable(solrRecord.getResult().getInstance()) |
112 | 112 |
.map(List::stream) // Convert the instance list to a stream if it's not null |
113 | 113 |
.orElseGet(Stream::empty) // Provide an empty stream if the instance is null |
114 |
.filter(instance -> "OPEN".equalsIgnoreCase(instance.getAccessright().getValue())) // Filter for "OPEN"
|
|
114 |
.filter(instance -> "OPEN".equalsIgnoreCase(instance.getAccessright().getCode())) // Filter for "OPEN"
|
|
115 | 115 |
.findFirst() // Find the first matching instance |
116 | 116 |
.map(instance -> |
117 | 117 |
Optional.ofNullable(instance.getUrl()) // Get the list of URLs |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/mappers/html/ResearchProductsHtmlMapper.java | ||
---|---|---|
19 | 19 |
@Mapping(target = "type", source = "result.resulttype") |
20 | 20 |
@Mapping(target = "title", source = "result.maintitle") |
21 | 21 |
@Mapping(target = "authors", expression = "java(extractAuthor(solrRecord))") |
22 |
@Mapping(target = "publicationYear", source = "result.publicationdate") |
|
22 |
@Mapping(target = "publicationYear", source = "result.publicationdate", defaultValue = "")
|
|
23 | 23 |
@Mapping(target = "doi", expression = "java(extractDoi(solrRecord))") |
24 | 24 |
@Mapping(target = "permanentIdentifier", expression = "java(extractPermanentIdentifier(solrRecord))") |
25 | 25 |
@Mapping(target = "publicationType", expression = "java(exctractPublicationType(solrRecord))") |
26 |
@Mapping(target = "journal", source = "result.journal.name") |
|
26 |
@Mapping(target = "journal", source = "result.journal.name", defaultValue = "")
|
|
27 | 27 |
@Mapping(target = "projectName_gaNumber", expression = "java(extractFunder(solrRecord))") |
28 | 28 |
@Mapping(target = "accessMode", source = "result.bestaccessright.label") |
29 | 29 |
ResearchProductHtml toResearchProductHtml(SolrRecord solrRecord); |
... | ... | |
37 | 37 |
.orElse(""); |
38 | 38 |
} |
39 | 39 |
|
40 |
default String extractPermanentIdentifier(SolrRecord solrRecord){ |
|
40 |
default String extractPermanentIdentifier(SolrRecord solrRecord) {
|
|
41 | 41 |
return Optional.ofNullable(solrRecord.getResult().getInstance()) |
42 |
.map(instances -> instances.stream() |
|
43 |
.findFirst() |
|
44 |
.map(instance -> Optional.ofNullable(instance.getUrl()) |
|
45 |
.filter(urls -> !urls.isEmpty()) |
|
46 |
.map(urls -> urls.get(0)).orElse("")) |
|
47 |
.orElse("")).toString(); |
|
42 |
.map(List::stream) // Convert the instance list to a stream if it's not null |
|
43 |
.orElseGet(Stream::empty) // Provide an empty stream if the instance is null |
|
44 |
.findFirst() // Find the first instance |
|
45 |
.map(instance -> |
|
46 |
Optional.ofNullable(instance.getUrl()) // Get the list of URLs |
|
47 |
.filter(urls -> !urls.isEmpty()) // Ensure the list is not empty |
|
48 |
.map(urls -> urls.get(0)) // Get the first URL from the list |
|
49 |
.orElse("")) // Return empty string if the list is empty |
|
50 |
.orElse(""); |
|
48 | 51 |
} |
49 | 52 |
|
50 | 53 |
default String exctractPublicationType(SolrRecord solrRecord){ |
... | ... | |
58 | 61 |
default String extractDoi(SolrRecord solrRecord) { |
59 | 62 |
return Optional.ofNullable(solrRecord.getPid()) |
60 | 63 |
.map(pids -> pids.stream() |
61 |
.filter(pid -> "doi".equalsIgnoreCase(pid.getType())) |
|
64 |
.filter(pid -> "doi".equalsIgnoreCase(pid.getTypeCode()))
|
|
62 | 65 |
.map(Pid::getValue) |
63 | 66 |
.collect(Collectors.joining(";"))) |
64 | 67 |
.orElse(""); |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/solr/SolrResultSet.java | ||
---|---|---|
34 | 34 |
import org.apache.solr.common.SolrDocumentList; |
35 | 35 |
import org.apache.solr.common.params.SolrParams; |
36 | 36 |
import org.apache.solr.common.util.NamedList; |
37 |
import org.springframework.beans.factory.annotation.Autowired; |
|
38 | 37 |
import org.z3950.zing.cql.CQLParseException; |
39 | 38 |
|
40 | 39 |
import javax.ws.rs.core.MediaType; |
... | ... | |
93 | 92 |
this.researchProductCsvConverter = researchProductCsvConverter; |
94 | 93 |
this.researchProductsHtmlMapper = researchProductsHtmlMapper; |
95 | 94 |
|
95 |
System.out.println("SOLR CLIENT " + solrClient); |
|
96 | 96 |
((CloudSolrClient)solrClient).setDefaultCollection(mdformat + "-" + layout + "-" + interpretation); |
97 | 97 |
|
98 | 98 |
this.registry = registry; |
... | ... | |
433 | 433 |
this.size = docs.getNumFound(); |
434 | 434 |
|
435 | 435 |
if (facetFields!=null && !facetFields.isEmpty()) { |
436 |
System.out.println("111111"); |
|
437 | 436 |
if (format != null && format.equals(MediaType.APPLICATION_JSON)) { |
438 |
System.out.println("22222"); |
|
439 | 437 |
for (FacetField field : facetFields) { |
440 |
System.out.println("33333 " + field.getValueCount()); |
|
441 | 438 |
map.put(field.getName(), new ArrayList<String>()); |
442 | 439 |
BrowseField bf = null; |
443 | 440 |
for (int i = 0; i < field.getValueCount(); i++) { |
444 |
System.out.println("44444"); |
|
445 | 441 |
bf = new BrowseField(); |
446 | 442 |
//bf.setId(org.apache.commons.lang3.StringEscapeUtils.escapeJson(field.getValues().get(i).getName())); |
447 | 443 |
bf.setId(field.getValues().get(i).getName()); |
448 | 444 |
String[] facetedValues = field.getValues().get(i).getName().split("\\|\\|",2); |
449 |
|
|
450 |
|
|
451 | 445 |
logger.debug("faceted values " + Arrays.toString(facetedValues)); |
452 |
System.out.println("faceted values " + Arrays.toString(facetedValues)); |
|
453 | 446 |
|
454 | 447 |
if (facetedValues.length > 1) { |
455 | 448 |
//bf.setName(org.apache.commons.lang3.StringEscapeUtils.escapeJson(facetedValues[1])); |
... | ... | |
466 | 459 |
} |
467 | 460 |
|
468 | 461 |
bf.setCount(field.getValues().get(i).getCount() + ""); |
469 |
System.out.println("skatakia:>:>" + new Gson().toJson(bf)); |
|
470 | 462 |
map.get(field.getName()).add(new Gson().toJson(bf)); |
471 | 463 |
} |
472 | 464 |
|
... | ... | |
511 | 503 |
if (format != null && format.equals(MediaType.APPLICATION_JSON)) { |
512 | 504 |
searchSolrResults.add(SolrResultsFormatter.xml2Json(result)); |
513 | 505 |
} else { // default xml*/ |
506 |
//System.out.println("Adding result"); |
|
507 |
// System.out.println("RESULT " + result); |
|
514 | 508 |
searchSolrResults.add(result); |
515 | 509 |
/*}*/ |
516 | 510 |
} |
... | ... | |
557 | 551 |
System.out.println("Datasource Mapper " + datasourceCsvMapper); |
558 | 552 |
|
559 | 553 |
int rows = 500; |
560 |
int limitCounter = -1; |
|
554 |
int limitCounter = (limit > 0) ? limit / rows : -1; |
|
555 |
int headerCounter = (limit > 0) ? limit / rows : -1; |
|
561 | 556 |
|
562 |
queryOpts.add("start", "0"); |
|
563 |
queryOpts.add("rows", "0"); |
|
564 |
queryOpts.remove("rows"); |
|
565 |
queryOpts.add("rows", rows+""); |
|
566 |
//queryOpts.add("fl", "__result"); |
|
567 |
queryOpts.add("shards.tolerant","true"); |
|
568 |
queryOpts.add("cursorMark", "*"); |
|
569 |
queryOpts.add("sort", "__indexrecordidentifier asc"); |
|
557 |
setupQueryOptions(rows); |
|
570 | 558 |
|
571 | 559 |
String cursorMark = "*"; |
572 | 560 |
String nextCursorMark = ""; |
573 | 561 |
|
574 |
if ( limit > 0 ) { |
|
575 |
limitCounter = limit/rows; |
|
576 |
logger.info("limit counter " + limitCounter); |
|
577 |
} |
|
578 |
|
|
579 | 562 |
try { |
580 |
QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
563 |
QueryResponse resp = null; |
|
564 |
if(isHtml) initializeHtmlTable(os); |
|
581 | 565 |
|
582 |
while (!cursorMark.equals(nextCursorMark) && ( limitCounter > 0 || limitCounter == -1)) { |
|
583 |
//logger.info(">> " + limitCounter); |
|
566 |
do { |
|
584 | 567 |
resp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
585 |
cursorMark = nextCursorMark; |
|
586 | 568 |
nextCursorMark = resp.getNextCursorMark(); |
587 | 569 |
|
588 |
StringBuilder htmlBuilder = null; |
|
570 |
for (int i = 0; i < resp.getResults().size(); i++) { |
|
571 |
SolrRecord record = objectMapper.readValue((String) resp.getResults().get(i).get("__json"), |
|
572 |
new TypeReference<SolrRecord>() {}); |
|
589 | 573 |
|
590 |
if(isHtml) { |
|
591 |
htmlBuilder = new StringBuilder(); |
|
592 |
// Start the HTML table and headers |
|
593 |
htmlBuilder.append("<table>") |
|
594 |
.append("<thead><tr>") |
|
595 |
.append("<th>Type</th>" + |
|
596 |
"<th>Title</th>" + |
|
597 |
"<th>Authors</th>" + |
|
598 |
"<th>Publication Year</th>" + |
|
599 |
"<th>DOI</th>" + |
|
600 |
"<th>Permanent Identifier</th>" + |
|
601 |
"<th>Publication type</th>" + |
|
602 |
"<th>Journal</th>" + |
|
603 |
"<th>Project Name (GA Number)</th>" + |
|
604 |
"<th>Access Mode</th>") // Add more headers as needed |
|
605 |
.append("</tr></thead><tbody>"); |
|
606 |
os.write(htmlBuilder.toString().getBytes()); |
|
607 |
os.flush(); |
|
608 |
} |
|
609 |
for (int i = 0; i < resp.getResults().size(); i++) { |
|
610 |
SolrRecord record = objectMapper.readValue((String) resp.getResults().get(i).get("__json"), new TypeReference<SolrRecord>() {}); |
|
611 | 574 |
if(!isHtml) { |
612 |
if (transformer != null) {
|
|
613 |
String result = null;
|
|
575 |
CsvEntity csvEntity = createCsvEntity(record);
|
|
576 |
CsvMapper csvMapper = selectCsvMapper(record);
|
|
614 | 577 |
|
578 |
if (hasTitle && i==0 && limitCounter == headerCounter) writeHeader(csvMapper, csvEntity, os); |
|
615 | 579 |
|
616 |
Datasource datasource = record.getDatasource(); |
|
617 |
Project project = record.getProject(); |
|
618 |
Result result1 = record.getResult(); |
|
619 |
Organization organization = record.getOrganization(); |
|
580 |
if (special) { |
|
581 |
List<ResearchProductCsv> flattenedProducts = researchProductCsvConverter.flattenProjects(record); |
|
582 |
CsvSchema schema = csvMapper.schemaFor(csvEntity.getClass()).withoutHeader(); |
|
583 |
ObjectWriter csvWriterRow = researchProductMapper.writer(schema); |
|
584 |
for (ResearchProductCsv internalCsvEntity : flattenedProducts) { |
|
620 | 585 |
|
621 |
System.out.println("datasource " + datasource); |
|
622 |
System.out.println("project " + project); |
|
623 |
System.out.println("result " + result); |
|
624 |
System.out.println("organization " + organization); |
|
625 |
|
|
626 |
CsvEntity csvEntity = null; |
|
627 |
String csvRow = ""; |
|
628 |
ObjectWriter csvWriterRow = null; |
|
629 |
|
|
630 |
if (datasource != null) { |
|
631 |
csvEntity = datasourceCsvMapper.toDatasourceCsv(record); |
|
632 |
CsvSchema schema = null; |
|
633 |
if (hasTitle) |
|
634 |
schema = datasourceMapper.schemaFor(DatasourceCsv.class).withHeader(); |
|
635 |
else |
|
636 |
schema = datasourceMapper.schemaFor(DatasourceCsv.class).withoutHeader(); |
|
637 |
//ObjectWriter csvWriterHeader = datasourceMapper.writer(schema); // Initialize for header |
|
638 |
csvWriterRow = datasourceMapper.writer(schema.withoutHeader()); |
|
639 |
} else if (organization != null) { |
|
640 |
csvEntity = organizationCsvMapper.toOrganizationCsv(record); |
|
641 |
CsvSchema schema = null; |
|
642 |
if (hasTitle) |
|
643 |
schema = organizationMapper.schemaFor(OrganizationCsv.class).withHeader(); |
|
644 |
else |
|
645 |
schema = organizationMapper.schemaFor(OrganizationCsv.class).withoutHeader(); |
|
646 |
//ObjectWriter csvWriterHeader = organizationMapper.writer(schema); // Initialize for header |
|
647 |
csvWriterRow = organizationMapper.writer(schema.withoutHeader()); |
|
648 |
} else if (project != null) { |
|
649 |
csvEntity = projectCsvMapper.toProjectCsv(record); |
|
650 |
CsvSchema schema = null; |
|
651 |
if (hasTitle) |
|
652 |
schema = projectMapper.schemaFor(ProjectCsv.class).withHeader(); |
|
653 |
else |
|
654 |
schema = projectMapper.schemaFor(ProjectCsv.class).withoutHeader(); |
|
655 |
//ObjectWriter csvWriterHeader = projectMapper.writer(schema); // Initialize for header |
|
656 |
csvWriterRow = projectMapper.writer(schema.withoutHeader()); |
|
657 |
} else if (result1 != null) { |
|
658 |
csvEntity = researchProductCsvMapper.toResearchProductCsv(record); |
|
659 |
CsvSchema schema = null; |
|
660 |
if (hasTitle) |
|
661 |
schema = researchProductMapper.schemaFor(ResearchProductCsv.class).withHeader(); |
|
662 |
else |
|
663 |
schema = researchProductMapper.schemaFor(ResearchProductCsv.class).withoutHeader(); |
|
664 |
//ObjectWriter csvWriterHeader = researchProductMapper.writer(schema); // Initialize for header |
|
665 |
csvWriterRow = researchProductMapper.writer(schema.withoutHeader()); |
|
586 |
String csvRow = csvWriterRow.writeValueAsString(internalCsvEntity); |
|
587 |
//System.out.println("CSV ROW special" + csvRow); |
|
588 |
os.write(csvRow.getBytes()); |
|
589 |
os.flush(); |
|
666 | 590 |
} |
667 | 591 |
|
668 |
try { |
|
669 |
if (!special) { |
|
670 |
csvRow = csvWriterRow.writeValueAsString(csvEntity); |
|
671 |
os.write(csvRow.getBytes()); |
|
672 |
os.flush(); |
|
673 |
} else { |
|
674 |
List<ResearchProductCsv> flattenedProducts = researchProductCsvConverter.flattenProjects(record); |
|
675 |
for (ResearchProductCsv internalCsvEntity : flattenedProducts) { |
|
676 |
csvRow = csvWriterRow.writeValueAsString(internalCsvEntity); |
|
677 |
os.write(csvRow.getBytes()); |
|
678 |
os.flush(); |
|
679 |
} |
|
680 |
} |
|
681 |
} catch (IOException e) { |
|
682 |
logger.error("Cursor get... ", e); |
|
683 |
System.out.println("ERROR " + e.getMessage()); |
|
684 |
continue; |
|
685 |
} |
|
592 |
} else { |
|
593 |
if (csvEntity != null && csvMapper != null) |
|
594 |
writeCsvEntity(csvMapper, csvEntity, special, os); |
|
686 | 595 |
} |
596 |
|
|
687 | 597 |
} else { |
688 |
ResearchProductHtml researchProductHtml = researchProductsHtmlMapper.toResearchProductHtml(record); |
|
689 |
htmlBuilder.append("<tr>") |
|
690 |
.append("<td>").append(researchProductHtml.getType()).append("</td>") |
|
691 |
.append("<td>").append(researchProductHtml.getTitle()).append("</td>") |
|
692 |
.append("<td>").append(researchProductHtml.getAuthors()).append("</td>") |
|
693 |
.append("<td>").append(researchProductHtml.getPublicationYear()).append("</td>") |
|
694 |
.append("<td>").append(researchProductHtml.getDoi()).append("</td>") |
|
695 |
.append("<td>").append(researchProductHtml.getPermanentIdentifier()).append("</td>") |
|
696 |
.append("<td>").append(researchProductHtml.getPublicationType()).append("</td>") |
|
697 |
.append("<td>").append(researchProductHtml.getJournal()).append("</td>") |
|
698 |
.append("<td>").append(researchProductHtml.getProjectName_gaNumber()).append("</td>") |
|
699 |
.append("<td>").append(researchProductHtml.getAccessMode()).append("</td>") |
|
700 |
.append("</tr>"); |
|
701 |
os.write(htmlBuilder.toString().getBytes()); |
|
702 |
os.flush(); |
|
598 |
writeHtmlRow(os, record); |
|
703 | 599 |
} |
704 | 600 |
} |
705 | 601 |
|
706 |
queryOpts.remove("cursorMark"); |
|
707 |
queryOpts.add("cursorMark", nextCursorMark); |
|
708 | 602 |
limitCounter--; |
709 |
}
|
|
603 |
updateCursorMark(nextCursorMark);
|
|
710 | 604 |
|
605 |
} while (!cursorMark.equals(nextCursorMark) && limitCounter != 0); |
|
606 |
|
|
711 | 607 |
} catch (IOException ioe) { |
712 | 608 |
logger.error("Error executing solr query. ", ioe); |
713 | 609 |
} |
714 | 610 |
} |
715 | 611 |
|
612 |
private void writeHtmlRow(OutputStream os, SolrRecord record) throws IOException { |
|
613 |
StringBuilder htmlBuilder = new StringBuilder(); |
|
614 |
ResearchProductHtml researchProductHtml = researchProductsHtmlMapper.toResearchProductHtml(record); |
|
615 |
htmlBuilder.append("<tr>") |
|
616 |
.append("<td>").append(researchProductHtml.getType()).append("</td>") |
|
617 |
.append("<td>").append(researchProductHtml.getTitle()).append("</td>") |
|
618 |
.append("<td>").append(researchProductHtml.getAuthors()).append("</td>") |
|
619 |
.append("<td>").append(researchProductHtml.getPublicationYear()).append("</td>") |
|
620 |
.append("<td>").append(researchProductHtml.getDoi()).append("</td>") |
|
621 |
.append("<td>").append(researchProductHtml.getPermanentIdentifier()).append("</td>") |
|
622 |
.append("<td>").append(researchProductHtml.getPublicationType()).append("</td>") |
|
623 |
.append("<td>").append(researchProductHtml.getJournal()).append("</td>") |
|
624 |
.append("<td>").append(researchProductHtml.getProjectName_gaNumber()).append("</td>") |
|
625 |
.append("<td>").append(researchProductHtml.getAccessMode()).append("</td>") |
|
626 |
.append("</tr>"); |
|
627 |
os.write(htmlBuilder.toString().getBytes()); |
|
628 |
os.flush(); |
|
629 |
} |
|
630 |
|
|
631 |
private CsvEntity createCsvEntity(SolrRecord solrRecord) { |
|
632 |
Datasource datasource = solrRecord.getDatasource(); |
|
633 |
Project project = solrRecord.getProject(); |
|
634 |
Result result = solrRecord.getResult(); |
|
635 |
Organization organization = solrRecord.getOrganization(); |
|
636 |
|
|
637 |
if (datasource != null) return datasourceCsvMapper.toDatasourceCsv(solrRecord); |
|
638 |
if (project != null) return projectCsvMapper.toProjectCsv(solrRecord); |
|
639 |
if (result != null) return researchProductCsvMapper.toResearchProductCsv(solrRecord); |
|
640 |
if (organization != null) return organizationCsvMapper.toOrganizationCsv(solrRecord); |
|
641 |
|
|
642 |
return null; |
|
643 |
} |
|
644 |
|
|
645 |
|
|
646 |
private CsvMapper selectCsvMapper(SolrRecord solrRecord) { |
|
647 |
Datasource datasource = solrRecord.getDatasource(); |
|
648 |
Project project = solrRecord.getProject(); |
|
649 |
Result result = solrRecord.getResult(); |
|
650 |
Organization organization = solrRecord.getOrganization(); |
|
651 |
|
|
652 |
if (datasource != null) return datasourceMapper; |
|
653 |
if (project != null) return projectMapper; |
|
654 |
if (result != null) return researchProductMapper; |
|
655 |
if (organization != null) return organizationMapper; |
|
656 |
|
|
657 |
return null; |
|
658 |
} |
|
659 |
|
|
660 |
|
|
661 |
private static void initializeHtmlTable(OutputStream os) throws IOException { |
|
662 |
StringBuilder htmlBuilder = new StringBuilder(); |
|
663 |
// Start the HTML table and headers |
|
664 |
htmlBuilder.append("<table>") |
|
665 |
.append("<thead><tr>") |
|
666 |
.append("<th>Type</th>" + |
|
667 |
"<th>Title</th>" + |
|
668 |
"<th>Authors</th>" + |
|
669 |
"<th>Publication Year</th>" + |
|
670 |
"<th>DOI</th>" + |
|
671 |
"<th>Permanent Identifier</th>" + |
|
672 |
"<th>Publication type</th>" + |
|
673 |
"<th>Journal</th>" + |
|
674 |
"<th>Project Name (GA Number)</th>" + |
|
675 |
"<th>Access Mode</th>") // Add more headers as needed |
|
676 |
.append("</tr></thead><tbody>"); |
|
677 |
os.write(htmlBuilder.toString().getBytes()); |
|
678 |
os.flush(); |
|
679 |
} |
|
680 |
|
|
681 |
public void writeHeader(CsvMapper csvMapper, CsvEntity csvEntity, OutputStream os) throws IOException { |
|
682 |
CsvSchema schema = csvMapper.schemaFor(csvEntity.getClass()).withHeader(); |
|
683 |
ObjectWriter csvWriterHeader = csvMapper.writer(schema); |
|
684 |
String csvHeader = csvWriterHeader.writeValueAsString(csvEntity.getClass()).split(System.lineSeparator())[0]; |
|
685 |
os.write(csvHeader.getBytes()); |
|
686 |
os.write("\n".getBytes()); |
|
687 |
os.flush(); |
|
688 |
|
|
689 |
} |
|
690 |
|
|
691 |
//TODO add special |
|
692 |
public void writeCsvEntity(CsvMapper csvMapper, CsvEntity csvEntity, boolean special, OutputStream os) throws IOException { |
|
693 |
CsvSchema schema = csvMapper.schemaFor(csvEntity.getClass()).withoutHeader(); |
|
694 |
ObjectWriter csvWriterRow = csvMapper.writer(schema.withoutHeader()); |
|
695 |
String csvRow = csvWriterRow.writeValueAsString(csvEntity); |
|
696 |
|
|
697 |
os.write(csvRow.getBytes()); |
|
698 |
os.flush(); |
|
699 |
} |
|
700 |
|
|
701 |
public void updateCursorMark(String nextCursorMark) { |
|
702 |
queryOpts.remove("cursorMark"); |
|
703 |
queryOpts.add("cursorMark", nextCursorMark); |
|
704 |
} |
|
705 |
|
|
706 |
private void setupQueryOptions(int rows) { |
|
707 |
queryOpts.add("start", "0"); |
|
708 |
queryOpts.add("rows", "0"); |
|
709 |
queryOpts.remove("rows"); |
|
710 |
queryOpts.add("rows", rows +""); |
|
711 |
//queryOpts.add("fl", "__result"); |
|
712 |
queryOpts.add("shards.tolerant","true"); |
|
713 |
queryOpts.add("cursorMark", "*"); |
|
714 |
queryOpts.add("sort", "__indexrecordidentifier asc"); |
|
715 |
} |
|
716 |
|
|
716 | 717 |
//TODO get rid of this as soon as Joomla portal is out |
717 | 718 |
//Just copied and refactored the old one... |
718 | 719 |
@Deprecated |
modules/uoa-search/branches/uoa-search-json/src/main/java/eu/dnetlib/data/search/web/api/SearchApiService.java | ||
---|---|---|
992 | 992 |
@Override |
993 | 993 |
public void write(OutputStream os) throws IOException, WebApplicationException |
994 | 994 |
{ |
995 |
if (hasTitle(format) && !format.equals("html")) { |
|
996 |
os.write(CSVResponseFormat.appendTitle(basicEntity, special).getBytes()); |
|
997 |
} |
|
995 |
|
|
998 | 996 |
try { |
999 | 997 |
((SearchServiceImpl)searchService).cursorSearch(fullquery, refineFields, null, fieldQueries, format, transformer, os, special, hasTitle(format) ,isHtml(format), 2000); |
1000 | 998 |
|
... | ... | |
1936 | 1934 |
} |
1937 | 1935 |
*/ |
1938 | 1936 |
|
1939 |
} |
|
1937 |
} |
Also available in: Unified diff
added and finalized html and csv converters