Skip to content

Commit

Permalink
UBO-351 Improved logging in UBOUserByConnectionResolver (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi authored Aug 12, 2024
1 parent f05e716 commit b1c370b
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@

package org.mycore.ubo;

import java.util.List;
import java.util.stream.Collectors;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;

import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.util.JAXBSource;
import org.apache.logging.log4j.LogManager;
Expand All @@ -35,6 +28,12 @@
import org.mycore.user2.MCRUserManager;
import org.mycore.user2.utils.MCRUserTransformer;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import java.util.List;
import java.util.stream.Collectors;

/**
* Resolves a User by connection id
*/
Expand All @@ -46,10 +45,18 @@ public class UBOUserByConnectionResolver implements URIResolver {
public Source resolve(String href, String base) throws TransformerException {
String connection_id = href.split(":", 2)[1];
final List<MCRUser> users = MCRUserManager.getUsers("id_connection", connection_id).collect(Collectors.toList());
if(users.size()!=1){
LOGGER.warn("There is a connection ID which has no User in DB {}", connection_id);

int size = users.size();
if (size != 1) {
if (size == 0) {
LOGGER.warn("Connection ID {} has no user in DB", connection_id);
}
if (size > 1) {
LOGGER.warn("Connection ID {} appears multiple times but for different users in DB", connection_id);
}
return new JDOMSource(new Element("null"));
}

final MCRUser user = users.get(0);

try {
Expand All @@ -58,5 +65,4 @@ public Source resolve(String href, String base) throws TransformerException {
throw new TransformerException(e);
}
}

}

0 comments on commit b1c370b

Please sign in to comment.