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

UBO-264 FSU040THUL-401 Added css class to badges indicating the class… #317

Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<jquery.version>3.5.1</jquery.version>
<mycore.version>2022.06.3-SNAPSHOT</mycore.version>
<node.version>v16.0.0</node.version>
<pica2mods.version>2.8-SNAPSHOT</pica2mods.version>
<sortpom.sortDeps>scope,groupId,artifactId</sortpom.sortDeps>
<sortpom.sortFile>https://gist.githubusercontent.com/yagee-de/dfd3698c1b49173dbf251f74eb6a9297/raw/406460c088ff3cb6354e4ae6b40535e6f841607d/mycore_sort.xml</sortpom.sortFile>
<sortpom.sortProps>true</sortpom.sortProps>
Expand Down Expand Up @@ -300,6 +301,11 @@
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-orcid2</artifactId>
<version>${mycore.version}</version>
</dependency>
<dependency>
<groupId>org.mycore.ubo</groupId>
<artifactId>ubo-cli</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions ubo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-orcid</artifactId>
<artifactId>mycore-orcid2</artifactId>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
Expand Down Expand Up @@ -344,7 +344,7 @@
<dependency>
<groupId>org.mycore.pica2mods</groupId>
<artifactId>pica2mods-xslt</artifactId>
<version>2.7-SNAPSHOT</version>
<version>${pica2mods.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,56 @@
package org.mycore.ubo.importer.orcid;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.MCRJDOMContent;
import org.mycore.common.content.transformer.MCRContentTransformer;
import org.mycore.orcid.MCRORCIDProfile;
import org.mycore.orcid.works.MCRWorksSection;
import org.xml.sax.SAXException;
import org.mycore.orcid2.MCRORCIDUtils;
import org.mycore.orcid2.client.exception.MCRORCIDRequestException;
import org.mycore.orcid2.v3.client.MCRORCIDClientHelper;
import org.mycore.orcid2.v3.client.MCRORCIDSectionImpl;
import org.mycore.orcid2.v3.work.MCRORCIDWorkUtils;
import org.orcid.jaxb.model.v3.release.record.Work;
import org.orcid.jaxb.model.v3.release.record.summary.WorkGroup;
import org.orcid.jaxb.model.v3.release.record.summary.WorkSummary;
import org.orcid.jaxb.model.v3.release.record.summary.Works;

public class Orcid2WorksTransformer extends MCRContentTransformer {

protected Logger LOGGER = LogManager.getLogger(Orcid2WorksTransformer.class);

public MCRJDOMContent transform(MCRContent source) throws IOException {
String orcid = source.asString();

MCRORCIDProfile profile = new MCRORCIDProfile(orcid);
try {
MCRWorksSection worksSection = profile.getWorksSection();
worksSection.fetchDetails();

Element modsCollection = worksSection.buildMODSCollection();
return new MCRJDOMContent(modsCollection);
} catch (JDOMException | SAXException ex) {
throw new IOException(ex);
}
List<Work> workList = new ArrayList<>();

Arrays.stream(source.asString().split("\\s"))
.filter(orcid -> orcid.trim().length() > 0)
.forEach(orcid -> {
try {
Works works = MCRORCIDClientHelper.getClientFactory().createReadClient().fetch(orcid,
MCRORCIDSectionImpl.WORKS, Works.class);

for (WorkGroup wg : works.getWorkGroup()) {
WorkSummary ws = wg.getWorkSummary().stream()
.filter(workSummary -> workSummary.getDisplayIndex().equals("1")).findFirst().get();

Work work = MCRORCIDClientHelper.getClientFactory().createReadClient().fetch(orcid,
MCRORCIDSectionImpl.WORK, Work.class, ws.getPutCode());
workList.add(work);
}
} catch (MCRORCIDRequestException e) {
LOGGER.warn("Could not get works for ORCID {}. {}", orcid, e.getMessage());
}
});

List<Element> workElements = MCRORCIDWorkUtils.buildUnmergedMODSFromWorks(workList);
Element modsCollection = MCRORCIDUtils.buildMODSCollection(workElements);

return new MCRJDOMContent(modsCollection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.mods.MCRMODSWrapper;
import org.mycore.orcid.user.MCRORCIDUser;
import org.mycore.orcid2.user.MCRORCIDUser;
import org.mycore.ubo.ldap.LDAPObject;
import org.mycore.user2.MCRRealmFactory;
import org.mycore.user2.MCRUser;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.mycore.ubo.orcid;

import java.io.IOException;
import java.util.Set;
import java.util.SortedSet;

import jakarta.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.MCRSessionMgr;
import org.mycore.common.xml.MCRXMLFunctions;
import org.mycore.frontend.MCRFrontendUtil;
import org.mycore.frontend.servlets.MCRServlet;
import org.mycore.frontend.servlets.MCRServletJob;
import org.mycore.orcid2.user.MCRORCIDSessionUtils;
import org.mycore.orcid2.user.MCRORCIDUser;
import org.mycore.orcid2.user.MCRORCIDUserUtils;
import org.mycore.user2.MCRUser;
import org.mycore.user2.MCRUserAttribute;
import org.mycore.user2.MCRUserManager;

/**
* Servlet removes all orcid access tokens of the current user. If you want to remove a single access token for
* a given orcid please see {@link org.mycore.orcid2.rest.resources.MCRORCIDResource#revoke(String)} )}
*
* @author shermann
* */
public class DozBibORCIDUserServlet extends MCRServlet {

public final static Logger LOGGER = LogManager.getLogger(DozBibORCIDUserServlet.class);

@Override
protected void doGetPost(MCRServletJob job) throws Exception {
if (MCRXMLFunctions.isCurrentUserGuestUser()) {
job.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
}

String action = job.getRequest().getParameter("action");
if (action == null) {
redirectToProfile(job);
return;
}

MCRORCIDUser orcidUser = MCRORCIDSessionUtils.getCurrentUser();
Set<String> orcidIdentifiers = orcidUser.getORCIDs();

if (orcidIdentifiers.isEmpty()) {
redirectToProfile(job);
return;
}

switch (action) {
case "sync":
toggleSync();
break;
case "revoke":
orcidUser.getUser()
.getAttributes()
.removeIf(a -> a.getName().equals("orcid_update_profile"));

orcidIdentifiers.forEach(orcid -> {
LOGGER.info("Unlinking ORCID {} for user {}", orcid, orcidUser.getUser().getUserID());
MCRORCIDUserUtils.revokeCredentialByORCID(orcidUser, orcid);
});
break;
}

redirectToProfile(job);
}

private void toggleSync() {
MCRUser user = MCRUserManager.getUser(MCRSessionMgr.getCurrentSession().getUserInformation().getUserID());
SortedSet<MCRUserAttribute> attributes = user.getAttributes();

attributes.stream()
.filter(attr -> attr.getName().equals("orcid_update_profile"))
.findFirst()
.ifPresentOrElse(present -> {
attributes.remove(present);
}, () -> {
attributes.add(new MCRUserAttribute("orcid_update_profile", String.valueOf(true)));
});
}

protected void redirectToProfile(MCRServletJob job) throws IOException {
job.getResponse().sendRedirect(MCRFrontendUtil.getBaseURL() + "servlets/MCRUserServlet?action=show");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.mycore.ubo.orcid;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.common.xml.MCRXMLFunctions;
import org.mycore.orcid2.client.MCRORCIDCredential;
import org.mycore.orcid2.client.MCRORCIDUserClient;
import org.mycore.orcid2.client.exception.MCRORCIDRequestException;
import org.mycore.orcid2.user.MCRORCIDSessionUtils;
import org.mycore.orcid2.user.MCRORCIDUser;
import org.mycore.orcid2.v3.client.MCRORCIDClientHelper;
import org.mycore.orcid2.v3.client.MCRORCIDSectionImpl;
import org.orcid.jaxb.model.v3.release.record.summary.Works;

public class DozBibORCIDUtils {

protected static final Logger LOGGER = LogManager.getLogger(DozBibORCIDUtils.class);

/**
* Get the total number of publications for all orcids connected with UBO.
*
* @return the total number of publications
* */
public static int getNumWorks() {
MCRORCIDUser orcidUser = MCRORCIDSessionUtils.getCurrentUser();
Set<String> orcidIdentifiers = orcidUser.getORCIDs();

AtomicInteger numWorks = new AtomicInteger(0);

orcidIdentifiers.forEach(orcid -> {
MCRORCIDCredential credential = orcidUser.getCredentialByORCID(orcid);
if (credential != null) {
try {
MCRORCIDUserClient client = MCRORCIDClientHelper.getClientFactory()
.createUserClient(orcid, credential);
Works works = client.fetch(MCRORCIDSectionImpl.WORKS, Works.class);
numWorks.addAndGet(works.getWorkGroup().size());
} catch (MCRORCIDRequestException e) {
LOGGER.error(e.getMessage(), e);
}
}
});

return numWorks.get();
}

/**
* Returns the number of publications for the given orcid. The orcid must be connected with UBO otherwise 0
* will be returned.
*
* @param orcid the orcid for which the number of publications will be retrieved
*
* @return the number of publications for the given orcid
* */
public static int getNumWorks(String orcid) {
MCRORCIDUser orcidUser = MCRORCIDSessionUtils.getCurrentUser();
MCRORCIDCredential credentialByORCID = orcidUser.getCredentialByORCID(orcid);

MCRORCIDUserClient client = MCRORCIDClientHelper.getClientFactory().createUserClient(orcid, credentialByORCID);
AtomicInteger numWorks = new AtomicInteger(0);

try {
Works works = client.fetch(MCRORCIDSectionImpl.WORKS, Works.class);
numWorks.addAndGet(works.getWorkGroup().size());
} catch (MCRORCIDRequestException e) {
LOGGER.error(e.getMessage(), e);
}

return numWorks.get();
}

public static String getFirstOrcidByCurrentUser() {
MCRORCIDUser orcidUser = MCRORCIDSessionUtils.getCurrentUser();
return orcidUser.getORCIDs().isEmpty() ? "" : orcidUser.getORCIDs().iterator().next();
}

public static boolean weAreTrustedParty() {
if (MCRXMLFunctions.isCurrentUserGuestUser()) {
return false;
}

MCRORCIDUser orcidUser = MCRORCIDSessionUtils.getCurrentUser();
Map<String, MCRORCIDCredential> credentials = orcidUser.getCredentials();

return !credentials.isEmpty();
}

public static boolean isConnected(String orcid) {
return MCRORCIDSessionUtils.getCurrentUser().getCredentialByORCID(orcid) != null;
}
}
Loading