Skip to content

Commit

Permalink
MCR-3229 enable PMD rule LooseCoupling
Browse files Browse the repository at this point in the history
  • Loading branch information
yagee-de committed Jan 10, 2025
1 parent 0a2cbcb commit a140dd3
Show file tree
Hide file tree
Showing 154 changed files with 759 additions and 684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MCRAccessCacheHelper {
public static void clearPermissionCache(String id) {
LOGGER.info("Invalidate all permissions for obj {} from local cache", id);

final ArrayList<String> idsToClear = new ArrayList<>();
List<String> idsToClear = new ArrayList<>();
idsToClear.add(id);
collectDescendants(idsToClear, id);
MCRAccessManager.invalidPermissionCacheByID(idsToClear.toArray(new String[0]));
Expand All @@ -53,7 +53,7 @@ public static void clearPermissionCache(String id) {
public static void clearAllPermissionCaches(String id) {
LOGGER.info("Invalidate all permissions for obj {} from all caches", id);

final ArrayList<String> idsToClear = new ArrayList<>();
List<String> idsToClear = new ArrayList<>();
idsToClear.add(id);
collectDescendants(idsToClear, id);
MCRAccessManager.invalidAllPermissionCachesById(idsToClear.toArray(new String[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -45,7 +46,7 @@
*/
public class MCRAccessControlSystem extends MCRAccessBaseImpl {
private static MCRAccessControlSystem singleton;
private static final HashMap<String, Integer> NEXT_FREE_RULE_ID = new HashMap<>();
private static final Map<String, Integer> NEXT_FREE_RULE_ID = new HashMap<>();

public static final String SYSTEM_RULE_PREFIX = "SYSTEMRULE";

Expand All @@ -61,14 +62,14 @@ public class MCRAccessControlSystem extends MCRAccessBaseImpl {

boolean disabled = false;

static Hashtable<String, String> ruleIDTable = new Hashtable<>();
static Map<String, String> ruleIDTable = new Hashtable<>();

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

private MCRAccessControlSystem() {
String pools = MCRConfiguration2.getString("MCR.Access.AccessPermissions").orElse("read,write,delete");

if (pools.trim().length() == 0) {
if (pools.isBlank()) {
disabled = true;
}

Expand Down Expand Up @@ -101,7 +102,7 @@ public void createRule(Element rule, String creator, String description) {
public void addRule(String id, String pool, Element rule, String description) throws MCRException {
MCRRuleMapping ruleMapping = getAutoGeneratedRuleMapping(rule, "System", pool, id, description);
String oldRuleID = accessStore.getRuleID(id, pool);
if (oldRuleID == null || oldRuleID.equals("")) {
if (oldRuleID == null || oldRuleID.isEmpty()) {
accessStore.createAccessDefinition(ruleMapping);
} else {
accessStore.updateAccessDefinition(ruleMapping);
Expand Down Expand Up @@ -135,7 +136,7 @@ public void removeAllRules(String id) throws MCRException {
public void updateRule(String id, String pool, Element rule, String description) throws MCRException {
MCRRuleMapping ruleMapping = getAutoGeneratedRuleMapping(rule, "System", pool, id, description);
String oldRuleID = accessStore.getRuleID(id, pool);
if (oldRuleID == null || oldRuleID.equals("")) {
if (oldRuleID == null || oldRuleID.isEmpty()) {
LOGGER.debug(
"updateRule called for id <{}> and pool <{}>, but no rule is existing, so new rule was created", id,
pool);
Expand Down Expand Up @@ -347,7 +348,7 @@ public synchronized String getNextFreeRuleID(String prefix) {
*/
@Override
public String getNormalizedRuleString(Element rule) {
if (rule.getChildren() == null || rule.getChildren().size() == 0) {
if (rule.getChildren() == null || rule.getChildren().isEmpty()) {
return "false";
}
Element normalizedRule = normalize(rule.getChildren().getFirst());
Expand All @@ -372,9 +373,9 @@ public MCRRuleMapping getAutoGeneratedRuleMapping(Element rule, String creator,
String description) {
String ruleString = getNormalizedRuleString(rule);
String ruleID = ruleIDTable.get(ruleString);
if (ruleID == null || ruleID.length() == 0) {
if (ruleID == null || ruleID.isEmpty()) {
Collection<String> existingIDs = ruleStore.retrieveRuleIDs(ruleString, description);
if (existingIDs != null && existingIDs.size() > 0) {
if (existingIDs != null && !existingIDs.isEmpty()) {
// rule yet exists
ruleID = existingIDs.iterator().next();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
package org.mycore.access.mcrimpl;

import java.util.HashMap;
import java.util.Map;

/**
* Maps object ids to rules
*
*
* @author Arne Seifert
*/
public class MCRAccessDefinition {

private String objid;

private HashMap<String, String> pools = new HashMap<>();
private Map<String, String> pools = new HashMap<>();

public MCRAccessDefinition() {
pools.clear();
Expand All @@ -43,11 +44,11 @@ public void setObjID(String value) {
objid = value;
}

public HashMap<String, String> getPool() {
public Map<String, String> getPool() {
return pools;
}

public void setPool(HashMap<String, String> pool) {
public void setPool(Map<String, String> pool) {
pools = pool;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.logging.log4j.LogManager;
Expand All @@ -37,7 +38,7 @@
* must implement this interface. Which database actually will be used can then
* be configured by reading the value <code>MCR.Persistence.Access.Store.Class</code>
* from mycore.properties.access
*
*
* @author Arne Seifert
*/
public abstract class MCRAccessStore {
Expand Down Expand Up @@ -71,7 +72,7 @@ public abstract class MCRAccessStore {
public abstract boolean isRuleInUse(String ruleid);

/**
*
*
* @return a collection of all String IDs an access rule is assigned to
*/
public abstract Collection<String> getDistinctStringIDs();
Expand All @@ -96,13 +97,13 @@ public static Collection<String> getPools() {
/**
* alle Elemente eines Datentypes aufbereiten
* @param type document type
*
*
* @return List of MCRAccessDefinition
* @see MCRAccessDefinition
*/
public Collection<MCRAccessDefinition> getDefinition(String type) {
try {
HashMap<String, Collection<String>> sqlDefinition = new HashMap<>();
Map<String, Collection<String>> sqlDefinition = new HashMap<>();
Collection<String> pools = getInstance().getDatabasePools();
//merge pools
pools.removeAll(getPools());
Expand Down
9 changes: 5 additions & 4 deletions mycore-base/src/main/java/org/mycore/common/MCRConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.logging.log4j.LogManager;
import org.jdom2.Namespace;
Expand All @@ -30,7 +31,7 @@
/**
* This class replaces the deprecated MCRDefaults interface and provides some
* final static fields of common use.
*
*
* @author Jens Kupferschmidt
* @author Thomas Scheffler (yagee)
* @author Stefan Freitag (sasf)
Expand Down Expand Up @@ -119,10 +120,10 @@ public final class MCRConstants {

public static final Namespace MCR_NAMESPACE = Namespace.getNamespace("mcr", MCR_URL);

private static final HashMap<String, Namespace> NAMESPACES_BY_PREFIX;
private static final Map<String, Namespace> NAMESPACES_BY_PREFIX;

static {
NAMESPACES_BY_PREFIX = new HashMap<>();
NAMESPACES_BY_PREFIX = new ConcurrentHashMap<>();

Field[] fields = MCRConstants.class.getFields();
for (Field f : fields) {
Expand Down
50 changes: 25 additions & 25 deletions mycore-base/src/main/java/org/mycore/common/MCRMailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@

/**
* This class provides methods to send emails from within a MyCoRe application.
*
*
* @author Marc Schluepmann
* @author Frank Lützenkirchen
* @author Werner Greßhoff
* @author René Adler (eagle)
*
*
*/
public class MCRMailer extends MCRServlet {

Expand Down Expand Up @@ -146,7 +146,7 @@ protected void doGetPost(MCRServletJob job) throws Exception {

/**
* This method sends a simple plaintext email with the given parameters.
*
*
* @param sender
* the sender of the email
* @param recipient
Expand All @@ -159,15 +159,15 @@ protected void doGetPost(MCRServletJob job) throws Exception {
public static void send(String sender, String recipient, String subject, String body) {
LOGGER.debug("Called plaintext send method with single recipient.");

ArrayList<String> recipients = new ArrayList<>();
List<String> recipients = new ArrayList<>();
recipients.add(recipient);
send(sender, null, recipients, null, subject, body, null);
}

/**
* This method sends a simple plaintext email to more than one recipient. If
* flag BCC is true, the sender will also get the email as BCC recipient.
*
*
* @param sender
* the sender of the email
* @param recipients
Expand All @@ -194,7 +194,7 @@ public static void send(String sender, List<String> recipients, String subject,

/**
* This method sends a multipart email with the given parameters.
*
*
* @param sender
* the sender of the email
* @param recipient
Expand All @@ -209,15 +209,15 @@ public static void send(String sender, List<String> recipients, String subject,
public static void send(String sender, String recipient, String subject, String body, List<String> parts) {
LOGGER.debug("Called multipart send method with single recipient.");

ArrayList<String> recipients = new ArrayList<>();
List<String> recipients = new ArrayList<>();
recipients.add(recipient);
send(sender, null, recipients, null, subject, body, parts);
}

/**
* This method sends a multipart email to more than one recipient. If flag
* BCC is true, the sender will also get the email as BCC recipient.
*
*
* @param sender
* the sender of the email
* @param recipients
Expand Down Expand Up @@ -302,8 +302,8 @@ public static void send(Element email, Boolean allowException) throws Exception
* Sends email. When sending email fails (for example, outgoing mail server
* is not responding), sending will be retried after five minutes. This is
* done up to 10 times.
*
*
*
*
* @param from
* the sender of the email
* @param replyTo
Expand Down Expand Up @@ -343,7 +343,7 @@ public static void send(final String from, final List<String> replyTo, final Lis
* Sends email. When sending email fails (for example, outgoing mail server
* is not responding), sending will be retried after five minutes. This is
* done up to 10 times.
*
*
* @param mail the email
*/
public static void send(EMail mail) {
Expand Down Expand Up @@ -457,12 +457,12 @@ private static void setMessageContent(EMail mail, Multipart multipart)
/**
* Generates e-mail from the given input document by transforming it with an xsl stylesheet,
* and sends the e-mail afterwards.
*
*
* @param input the xml input document
* @param stylesheet the xsl stylesheet that will generate the e-mail, without the ending ".xsl"
* @param stylesheet the xsl stylesheet that will generate the e-mail, without the ending ".xsl"
* @param parameters the optionally empty table of xsl parameters
* @return the generated e-mail
*
*
* @see org.mycore.common.MCRMailer
*/
public static Element sendMail(Document input, String stylesheet, Map<String, String> parameters) throws Exception {
Expand All @@ -489,20 +489,20 @@ public static Element sendMail(Document input, String stylesheet, Map<String, St
/**
* Generates e-mail from the given input document by transforming it with an xsl stylesheet,
* and sends the e-mail afterwards.
*
*
* @param input the xml input document
* @param stylesheet the xsl stylesheet that will generate the e-mail, without the ending ".xsl"
* @param stylesheet the xsl stylesheet that will generate the e-mail, without the ending ".xsl"
* @return the generated e-mail
*
*
* @see org.mycore.common.MCRMailer
*/
public static Element sendMail(Document input, String stylesheet) throws Exception {
return sendMail(input, stylesheet, Collections.emptyMap());
}

/**
/**
* Transforms the given input element using xsl stylesheet.
*
*
* @param input the input document to transform.
* @param stylesheet the name of the xsl stylesheet to use, without the ".xsl" ending.
* @param parameters the optionally empty table of xsl parameters
Expand Down Expand Up @@ -561,7 +561,7 @@ private static JAXBContext initContext() {

/**
* Parse a email from given {@link Element}.
*
*
* @param xml the email
* @return the {@link EMail} object
*/
Expand All @@ -578,7 +578,7 @@ public static EMail parseXML(final Element xml) {
* Builds email address from a string. The string may be a single email
* address or a combination of a personal name and address, like "John Doe"
* &lt;[email protected]&gt;
*
*
* @param s the email address string
* @return a {@link InternetAddress}
* @throws Exception throws AddressException or UnsupportedEncodingException
Expand All @@ -600,7 +600,7 @@ private static InternetAddress buildAddress(String s) throws Exception {

/**
* Builds a list of email addresses from a string list.
*
*
* @param addresses the list with email addresses
* @return a list of {@link InternetAddress}s
* @see MCRMailer.EMail#buildAddress(String)
Expand All @@ -617,7 +617,7 @@ private static Optional<List<InternetAddress>> buildAddressList(final List<Strin

/**
* Returns the text message part.
*
*
* @return the text message part
*/
public Optional<MessagePart> getTextMessage() {
Expand All @@ -627,7 +627,7 @@ public Optional<MessagePart> getTextMessage() {

/**
* Returns the HTML message part.
*
*
* @return the HTML message part
*/
public Optional<MessagePart> getHTMLMessage() {
Expand All @@ -637,7 +637,7 @@ public Optional<MessagePart> getHTMLMessage() {

/**
* Returns the {@link EMail} as XML.
*
*
* @return the XML
*/
public Document toXML() {
Expand Down
Loading

0 comments on commit a140dd3

Please sign in to comment.