Skip to content

Commit

Permalink
refactoring logicaldoc-core with @Resources annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
gdesiato committed Feb 3, 2025
1 parent 0517623 commit 68116ed
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
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 @@ -57,31 +58,24 @@ public class FormatConverterManager {

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

private Store store;

private TenantDAO tenantDao;
@Resource(name = "Store")
protected Store store;

private DocumentManager documentManager;
@Resource(name = "TenantDAO")
protected TenantDAO tenantDao;

private ContextProperties config;
@Resource(name = "documentManager")
protected DocumentManager documentManager;

@Resource(name = "ContextProperties")
protected ContextProperties config;
// Key is the src_extension-dst_extension, value is a collection of
// converters
private Map<String, List<FormatConverter>> converters = new HashMap<>();

// All the available converters
private Map<String, FormatConverter> availableConverters = new HashMap<>();

@Autowired
public FormatConverterManager(Store store, TenantDAO tenantDao, DocumentManager documentManager,
ContextProperties config) {
super();
this.store = store;
this.tenantDao = tenantDao;
this.documentManager = documentManager;
this.config = config;
}

/**
* Retrieves the content of the Pdf conversion. If the Pdf conversion is not
* available in the store, it is created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;

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

import com.logicaldoc.core.PersistenceException;
Expand All @@ -23,19 +24,19 @@
public class DigestProcessor extends Task {
public static final String NAME = "DigestProcessor";

private DocumentDAO documentDao;
@Resource(name = "DocumentDAO")
protected DocumentDAO documentDao;

private long processed = 0;

private long errors = 0;

@Autowired
public DigestProcessor(DocumentDAO documentDao) {
public DigestProcessor() {
super(NAME);
log = LoggerFactory.getLogger(DigestProcessor.class);
this.documentDao = documentDao;
}


@Override
public boolean isIndeterminate() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -90,49 +91,41 @@ public class DocumentManagerImpl implements DocumentManager {

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

private DocumentDAO documentDAO;

private DocumentLinkDAO documentLinkDAO;
@Resource(name = "DocumentDAO")
protected DocumentDAO documentDAO;

private DocumentNoteDAO documentNoteDAO;
@Resource(name = "DocumentLinkDAO")
protected DocumentLinkDAO documentLinkDAO;

private FolderDAO folderDAO;
@Resource(name = "DocumentNoteDAO")
protected DocumentNoteDAO documentNoteDAO;

private TemplateDAO templateDAO;
@Resource(name = "FolderDAO")
protected FolderDAO folderDAO;

private DocumentListenerManager listenerManager;
@Resource(name = "TemplateDAO")
protected TemplateDAO templateDAO;

private VersionDAO versionDAO;
@Resource(name = "documentListenerManager")
protected DocumentListenerManager listenerManager;

private UserDAO userDAO;
@Resource(name = "VersionDAO")
protected VersionDAO versionDAO;

private TicketDAO ticketDAO;
@Resource(name = "UserDAO")
protected UserDAO userDAO;

private SearchEngine indexer;
@Resource(name = "TicketDAO")
protected TicketDAO ticketDAO;

private Store store;
@Resource(name = "SearchEngine")
protected SearchEngine indexer;

private ContextProperties config;
@Resource(name = "Store")
protected Store store;

@Autowired
public DocumentManagerImpl(DocumentDAO documentDAO, DocumentLinkDAO documentLinkDAO,
DocumentNoteDAO documentNoteDAO, FolderDAO folderDAO, TemplateDAO templateDAO,
DocumentListenerManager listenerManager, VersionDAO versionDAO, UserDAO userDAO, TicketDAO ticketDAO,
SearchEngine indexer, Store store, ContextProperties config) {
super();
this.documentDAO = documentDAO;
this.documentLinkDAO = documentLinkDAO;
this.documentNoteDAO = documentNoteDAO;
this.folderDAO = folderDAO;
this.templateDAO = templateDAO;
this.listenerManager = listenerManager;
this.versionDAO = versionDAO;
this.userDAO = userDAO;
this.ticketDAO = ticketDAO;
this.indexer = indexer;
this.store = store;
this.config = config;
}
@Resource(name = "ContextProperties")
protected ContextProperties config;

@Override
public void replaceFile(long docId, String fileVersion, InputStream content, DocumentHistory transaction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

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 @@ -29,9 +27,8 @@ public class HibernateDocumentHistoryDAO extends HibernateHistoryDAO<DocumentHis

private static final String AND = " and ";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import java.util.List;
import java.util.Set;

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 @@ -31,16 +32,15 @@ public class HibernateVersionDAO extends HibernatePersistentObjectDAO<Version> i

private static final String DOC_ID = ".docId=";

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

private FolderDAO folderDAO;
@Resource(name = "FolderDAO")
protected FolderDAO folderDAO;

@Autowired
private HibernateVersionDAO(Store store, FolderDAO folderDAO) {
public HibernateVersionDAO() {
super(Version.class);
super.log = LoggerFactory.getLogger(HibernateVersionDAO.class);
this.store = store;
this.folderDAO = folderDAO;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.logicaldoc.core.document;

import javax.annotation.Resource;

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

import com.logicaldoc.core.PersistenceException;
Expand All @@ -20,13 +21,13 @@ public class TagsProcessor extends Task {

public static final String NAME = "TagsProcessor";

private final DocumentDAO documentDao;
@Resource(name = "DocumentDAO")
private DocumentDAO documentDao;


@Autowired
public TagsProcessor(DocumentDAO documentDao) {
public TagsProcessor() {
super(NAME);
log = LoggerFactory.getLogger(TagsProcessor.class);
this.documentDao = documentDao;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import java.util.StringTokenizer;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;

Expand Down Expand Up @@ -95,23 +96,21 @@ public class HibernateFolderDAO extends HibernatePersistentObjectDAO<Folder> imp

private static final String WHERE_GROUP_GROUPID_IN = " where _group.groupId in (";

private UserDAO userDAO;
@Resource(name = "UserDAO")
protected UserDAO userDAO;

private FolderHistoryDAO historyDAO;
@Resource(name = "FolderHistoryDAO")
protected FolderHistoryDAO historyDAO;

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

private FolderListenerManager listenerManager;
@Resource(name = "folderListenerManager")
protected FolderListenerManager listenerManager;

@Autowired
protected HibernateFolderDAO(UserDAO userDAO, FolderHistoryDAO historyDAO, Store store,
FolderListenerManager listenerManager) {
public HibernateFolderDAO() {
super(Folder.class);
super.log = LoggerFactory.getLogger(HibernateFolderDAO.class);
this.userDAO = userDAO;
this.historyDAO = historyDAO;
this.store = store;
this.listenerManager = listenerManager;
}

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

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 @@ -29,9 +27,8 @@ public class HibernateFolderHistoryDAO extends HibernateHistoryDAO<FolderHistory

private static final String ORDER_BY = "order by ";

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

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

import java.util.List;

import javax.annotation.Resource;

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

import com.logicaldoc.core.PersistenceException;
Expand All @@ -21,18 +22,17 @@
public class PathCalculator extends Task {

public static final String NAME = "PathCalculator";

private FolderDAO folderDao;

@Resource(name = "FolderDAO")
protected FolderDAO folderDao;

private long processed = 0;

private long errors = 0;

@Autowired
public PathCalculator(FolderDAO folderDao) {
public PathCalculator() {
super(NAME);
log = LoggerFactory.getLogger(PathCalculator.class);
this.folderDao = folderDao;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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 @@ -28,16 +29,15 @@
public abstract class HibernateHistoryDAO<T extends History> extends HibernatePersistentObjectDAO<T>
implements PersistentObjectDAO<T> {

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

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

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

@Override
Expand Down
Loading

0 comments on commit 68116ed

Please sign in to comment.