Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  UBO-300 Flip parts of name in PersonResult list
  UBO-299 Fixed ZDB import of publisher information
  Add MARC Genre Term mapping for research_data
  UBO-296 Made indexing of year independent of actual position of the mods:originInfo/mods:dateIssued element (#347)
  UBO-288 publication event handler needs refactoring (#346)
  UBO-297 Implement command to export selected publications via CLI
  • Loading branch information
kkrebs committed Feb 6, 2024
2 parents c9d82cb + 5ecd093 commit ec13147
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 142 deletions.
1 change: 1 addition & 0 deletions ubo-cli/src/main/setup/classifications/ubogenre.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<label xml:lang="x-hosts" text="standalone" />
<label xml:lang="de" text="Forschungsdaten" />
<label xml:lang="en" text="research data" />
<label xml:lang="x-marcgt" text="database" />
</category>
</categories>
</mycoreclass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.mycore.ubo.export;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.MCRException;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.transformer.MCRContentTransformer;
import org.mycore.common.content.transformer.MCRContentTransformerFactory;
import org.mycore.frontend.basket.MCRBasket;
import org.mycore.frontend.basket.MCRBasketEntry;
import org.mycore.frontend.basket.MCRBasketManager;
import org.mycore.frontend.cli.MCRObjectCommands;
import org.mycore.frontend.cli.annotation.MCRCommand;
import org.mycore.frontend.cli.annotation.MCRCommandGroup;
import org.mycore.frontend.export.MCRExportCollection;

/**
* @author Frank L\u00FCtzenkirchen
*/
@MCRCommandGroup(name = "UBO export commands")
public class MCRExportCommands {

private static final Logger LOGGER = LogManager.getLogger();

@MCRCommand(
syntax = "ubo export selected using transformer {0} to file {1}",
help = "Exports previously selected objects using the transformer with the ID {0} and writes the output to file {1}",
order = 1)
public static void export(String transformerID, String pathOfOutputFile) throws IOException {
List<String> objectIDs = MCRObjectCommands.getSelectedObjectIDs();
LOGGER.info("Exporting {} objects using transformer {}...", objectIDs.size(), transformerID);

MCRContent source = buildExportCollection(objectIDs);
MCRContentTransformer transformer = MCRContentTransformerFactory.getTransformer(transformerID);
MCRContent result = transformer.transform(source);

LOGGER.info("Writing transformed output to file {}", pathOfOutputFile);
result.sendTo(new File(pathOfOutputFile));
}

private static MCRContent buildExportCollection(List<String> objectIDs) {
MCRBasket basket = MCRBasketManager.getOrCreateBasketInSession("objects");
objectIDs.forEach(objectID -> {
basket.add(new MCRBasketEntry(objectID, "mcrobject:" + objectID));
});

MCRExportCollection collection = new MCRExportCollection();
try {
collection.add(basket);
} catch (Exception ex) {
throw new MCRException(ex);
}

basket.clear();
return collection.getContent();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mycore.ubo.ldap.picker;

import java.util.List;
import java.util.Optional;

import javax.naming.OperationNotSupportedException;
Expand All @@ -19,6 +20,7 @@ public PersonSearchResult searchPerson(String query) throws OperationNotSupporte
PersonSearchResult results = super.searchPerson(query);
LocalService localService = new LocalService();
PersonSearchResult personSearchResult = localService.searchPerson(query);
flipNameParts(personSearchResult.personList);
results.join(personSearchResult, 0);

if (LDAP_REALM != null) {
Expand All @@ -28,4 +30,21 @@ public PersonSearchResult searchPerson(String query) throws OperationNotSupporte

return results;
}

protected void flipNameParts(List<PersonSearchResult.PersonResult> list) {
for (PersonSearchResult.PersonResult p : list) {
// split at ',' and remove leading and trailing spaces
String[] parts = p.displayName.split("\\s*,\\s*");

if (parts.length > 1) {
String firstName = parts[1];
String lastName = parts[0];

// set name parts with new values
p.firstName = firstName;
p.lastName = lastName;
p.displayName = p.firstName + " " + p.lastName;
}
}
}
}
Loading

0 comments on commit ec13147

Please sign in to comment.