Skip to content

Commit

Permalink
Constructor refactored with config
Browse files Browse the repository at this point in the history
  • Loading branch information
gdesiato committed Jan 30, 2025
1 parent cb09205 commit 5abe8c1
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Queue;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -20,7 +18,6 @@
import com.logicaldoc.core.history.History;
import com.logicaldoc.core.threading.ThreadPools;
import com.logicaldoc.util.Context;
import com.logicaldoc.util.config.ContextProperties;

/**
* A collector of events that can distribute them to a set of listeners
Expand All @@ -39,12 +36,8 @@ public class EventCollector {

private Set<EventListener> listeners = new HashSet<>();

@Resource(name = "ContextProperties")
private ContextProperties config;

public EventCollector(ContextProperties config) {
public EventCollector() {
super();
this.config = config;
}

// Maintain a fifos for the history IDs. Key is the class name, value is a
Expand Down Expand Up @@ -133,10 +126,6 @@ public void newEvent(History history) {
pools.execute(notifier, "EventCollector");
}

public ContextProperties getConfig() {
return config;
}

public static boolean isEnabled() {
return RunLevel.current().aspectEnabled(ASPECT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.java.plugin.registry.Extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.logicaldoc.core.PersistenceException;
Expand Down Expand Up @@ -58,16 +57,12 @@ public class FormatConverterManager {

protected static Logger log = LoggerFactory.getLogger(FormatConverterManager.class);

@Resource(name = "Store")
private Store store;

@Resource(name = "TenantDAO")
private TenantDAO tenantDao;

@Resource(name = "documentManager")
private DocumentManager documentManager;

@Resource(name = "ContextProperties")
private ContextProperties config;

// Key is the src_extension-dst_extension, value is a collection of
Expand All @@ -77,6 +72,7 @@ public class FormatConverterManager {
// All the available converters
private Map<String, FormatConverter> availableConverters = new HashMap<>();

@Autowired
public FormatConverterManager(Store store, TenantDAO tenantDao, DocumentManager documentManager,
ContextProperties config) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logicaldoc.core.PersistenceException;
import com.logicaldoc.core.history.HibernateHistoryDAO;
import com.logicaldoc.util.config.ContextProperties;
import com.logicaldoc.util.sql.SqlUtil;

/**
Expand All @@ -27,8 +29,9 @@ public class HibernateDocumentHistoryDAO extends HibernateHistoryDAO<DocumentHis

private static final String AND = " and ";

private HibernateDocumentHistoryDAO() {
super(DocumentHistory.class);
@Autowired
private HibernateDocumentHistoryDAO(ContextProperties config) {
super(DocumentHistory.class, config);
super.log = LoggerFactory.getLogger(HibernateDocumentHistoryDAO.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logicaldoc.core.PersistenceException;
import com.logicaldoc.core.history.HibernateHistoryDAO;
import com.logicaldoc.util.config.ContextProperties;
import com.logicaldoc.util.sql.SqlUtil;

/**
Expand All @@ -27,8 +29,9 @@ public class HibernateFolderHistoryDAO extends HibernateHistoryDAO<FolderHistory

private static final String ORDER_BY = "order by ";

private HibernateFolderHistoryDAO() {
super(FolderHistory.class);
@Autowired
private HibernateFolderHistoryDAO(ContextProperties config) {
super(FolderHistory.class, config);
super.log = LoggerFactory.getLogger(HibernateFolderHistoryDAO.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logicaldoc.core.HibernatePersistentObjectDAO;
import com.logicaldoc.core.PersistenceException;
Expand All @@ -21,24 +20,24 @@
/**
* Parent of all DAOs that handle histories
*
* @param <T> Class of the implementation of a {@link History} this DAO
* handles
* @param <T> Class of the implementation of a {@link History} this DAO handles
*
* @author Alessandro Gasparini - LogicalDOC
* @since 9.0.1
*/
public abstract class HibernateHistoryDAO<T extends History> extends HibernatePersistentObjectDAO<T>
implements PersistentObjectDAO<T> {

@Resource(name = "ContextProperties")
private ContextProperties config;

// A cache of tenant names to minimize the DB accesses
private static final Map<Long, String> tenantNames = new HashMap<>();

protected HibernateHistoryDAO(Class<T> historyClass) {
@Autowired
protected HibernateHistoryDAO(Class<T> historyClass, ContextProperties config) {
super(historyClass);
super.log = LoggerFactory.getLogger(HibernateHistoryDAO.class);
this.config = config;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
Expand All @@ -27,6 +25,7 @@
import org.quartz.impl.matchers.GroupMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.logicaldoc.util.config.ContextProperties;
Expand All @@ -49,12 +48,11 @@ public class JobManager {

protected static Logger log = LoggerFactory.getLogger(JobManager.class);

@Resource(name = "Scheduler")
private Scheduler scheduler;

@Resource(name = "ContextProperties")
private ContextProperties config;

@Autowired
public JobManager(Scheduler scheduler, ContextProperties config) {
super();
this.scheduler = scheduler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import java.util.GregorianCalendar;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.logicaldoc.core.PersistenceException;
Expand All @@ -30,12 +29,11 @@ public class LockManager {

protected Logger log = LoggerFactory.getLogger(LockManager.class);

@Resource(name = "GenericDAO")
private GenericDAO genericDao;

@Resource(name = "ContextProperties")
private ContextProperties config;


@Autowired
public LockManager(GenericDAO genericDao, ContextProperties config) {
super();
this.genericDao = genericDao;
Expand Down Expand Up @@ -83,7 +81,7 @@ public boolean get(String lockName, String transactionId) {
log.warn(e.getMessage(), e);
} catch (InterruptedException ie) {
log.warn("Interrupted", ie);

// Restore interrupted state
Thread.currentThread().interrupt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@

import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logicaldoc.core.PersistenceException;
import com.logicaldoc.core.history.HibernateHistoryDAO;
import com.logicaldoc.core.security.Client;
import com.logicaldoc.core.security.Session;
import com.logicaldoc.core.security.SessionManager;
import com.logicaldoc.util.config.ContextProperties;

public class HibernateUserHistoryDAO extends HibernateHistoryDAO<UserHistory> implements UserHistoryDAO {

private HibernateUserHistoryDAO() {
super(UserHistory.class);
@Autowired
private HibernateUserHistoryDAO(ContextProperties config) {
super(UserHistory.class, config);
super.log = LoggerFactory.getLogger(HibernateUserHistoryDAO.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.management.MBeanServerConnection;

import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.logicaldoc.util.config.ContextProperties;
Expand All @@ -29,7 +29,6 @@ public class SystemLoadMonitor {

protected static Logger log = LoggerFactory.getLogger(SystemLoadMonitor.class);

@Resource(name = "ContextProperties")
private ContextProperties config;

private CircularFifoQueue<Integer> samples = null;
Expand All @@ -41,7 +40,8 @@ public class SystemLoadMonitor {
private List<SystemLoadListener> listeners = new ArrayList<>();

private boolean lastCheckOverloaded = false;


@Autowired
public SystemLoadMonitor(ContextProperties config) {
super();
this.config = config;
Expand Down
18 changes: 0 additions & 18 deletions logicaldoc-util/src/main/java/com/logicaldoc/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.text.DecimalFormatSymbols;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Locale;

Expand Down Expand Up @@ -248,21 +247,4 @@ public static String printFileSize(long size, Locale locale) {
public static String defaultString(String input, String def) {
return StringUtils.defaultString(input, def);
}


/**
* Checks if a give n string is base64 coded
*
* @param value The tring to evaluate
*
* @return true only if value is base64 coded
*/
public static boolean isBase64(String value) {
try {
Base64.getDecoder().decode(value);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.logicaldoc.util.StringUtil;
import com.logicaldoc.util.io.FileUtil;

/**
Expand All @@ -34,6 +33,8 @@
*/
public class ContextProperties extends OrderedProperties {

private static final String BASE64_PREFIX = "_b64_";

private static final String UNABLE_TO_READ_FROM = "Unable to read from %s";

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -137,7 +138,7 @@ public ContextProperties(File file) throws IOException {
this.file = file;
FileUtils.touch(file);
try (FileInputStream fis = new FileInputStream(file)) {
load(fis);
load(fis);
}
} catch (IOException e) {
throw new IOException("Unable to read from " + file.getPath(), e);
Expand Down Expand Up @@ -267,10 +268,9 @@ public String getString(String property) {

public String getString(String property, String defaultValue) {
String value = getProperty(property, defaultValue);
if (StringUtil.isBase64(value)) {
byte[] decodedBytes = Base64.getDecoder().decode(value);
value = new String(decodedBytes);
}
if (value.startsWith(BASE64_PREFIX))
value = new String(Base64.getDecoder().decode(value.substring(BASE64_PREFIX.length())),
Charset.forName("UTF-8"));
return StrSubstitutor.replaceSystemProperties(value);
}

Expand Down Expand Up @@ -334,7 +334,7 @@ public float getFloat(String property, float defaultValue) {
@Override
public synchronized Object setProperty(String key, String value) {
if (value.contains("\n"))
value = Base64.getEncoder().encodeToString(value.getBytes(Charset.forName("UTF-8")));
value = BASE64_PREFIX + Base64.getEncoder().encodeToString(value.getBytes(Charset.forName("UTF-8")));
return super.setProperty(key, value);
}

Expand All @@ -360,11 +360,11 @@ public String getProperty(String property) {
* @return the porperty's value with expanded variables
*/
@Override
public String getProperty(String property, String defaultValue) {
public String getProperty(String property, String defaultValue) {
String value = super.getProperty(property, defaultValue);
return StrSubstitutor.replaceSystemProperties(value);
}

public int getMaxBackups() {
return maxBackups;
}
Expand Down
Loading

0 comments on commit 5abe8c1

Please sign in to comment.