Skip to content

Commit

Permalink
Refactored the way we get the beans from the Context
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Dec 20, 2024
1 parent f56d387 commit 2bd4458
Show file tree
Hide file tree
Showing 176 changed files with 963 additions and 1,362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public LDCmisService(CallContext context, String sid) {
this.sid = sid;

try {
historyDao = Context.get().getBean(DocumentHistoryDAO.class);
historyDao = Context.get(DocumentHistoryDAO.class);

FolderDAO fdao = Context.get().getBean(FolderDAO.class);
FolderDAO fdao = Context.get(FolderDAO.class);
Session session = SessionManager.get().get(sid);
Folder root = fdao.findRoot(session.getTenantId());

Expand Down
28 changes: 14 additions & 14 deletions logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ public LDRepository(Folder root, String sid) {
if (root == null)
throw new IllegalArgumentException("Invalid root folder!");

userDao = Context.get().getBean(UserDAO.class);
folderDao = Context.get().getBean(FolderDAO.class);
documentDao = Context.get().getBean(DocumentDAO.class);
documentManager = Context.get().getBean(DocumentManager.class);
templateDao = Context.get().getBean(TemplateDAO.class);
versionDao = Context.get().getBean(VersionDAO.class);
historyDao = Context.get().getBean(DocumentHistoryDAO.class);
folderHistoryDao = Context.get().getBean(FolderHistoryDAO.class);
userDao = Context.get(UserDAO.class);
folderDao = Context.get(FolderDAO.class);
documentDao = Context.get(DocumentDAO.class);
documentManager = Context.get(DocumentManager.class);
templateDao = Context.get(TemplateDAO.class);
versionDao = Context.get(VersionDAO.class);
historyDao = Context.get(DocumentHistoryDAO.class);
folderHistoryDao = Context.get(FolderHistoryDAO.class);

ContextProperties config = Context.get().getProperties();

Expand Down Expand Up @@ -549,7 +549,7 @@ public void appendContent(CallContext context, String documentId, ContentStream

NumberFormat nd = new DecimalFormat("0000000000");

Store store = Context.get().getBean(Store.class);
Store store = Context.get(Store.class);

File chunksFolder = getChunksFolder(documentId);
String resourceName = store.getResourceName(doc.getId(), doc.getFileVersion(), null);
Expand All @@ -566,7 +566,7 @@ public void appendContent(CallContext context, String documentId, ContentStream
if (isLastChunk) {
try {
File mergeFile = getMergedContent(chunksFolder);
DocumentManager manager = Context.get().getBean(DocumentManager.class);
DocumentManager manager = Context.get(DocumentManager.class);

DocumentHistory transaction = new DocumentHistory();
transaction.setUser(getSessionUser(context));
Expand Down Expand Up @@ -1187,7 +1187,7 @@ public ContentStream getContentStream(CallContext context, String objectId, BigI
AbstractDocument doc = getDocument(objectId);

InputStream stream = null;
Store store = Context.get().getBean(Store.class);
Store store = Context.get(Store.class);
InputStream is = null;
if (doc instanceof Document document) {
is = store.getStream(doc.getId(), store.getResourceName(document, null, null));
Expand Down Expand Up @@ -1237,7 +1237,7 @@ public ContentStream getContentStream(CallContext context, String objectId, BigI

private void saveHistory(DocumentHistory transaction) {
try {
DocumentHistoryDAO historyDAO = Context.get().getBean(DocumentHistoryDAO.class);
DocumentHistoryDAO historyDAO = Context.get(DocumentHistoryDAO.class);
historyDAO.store(transaction);
} catch (PersistenceException t) {
log.warn(t.getMessage(), t);
Expand Down Expand Up @@ -1512,7 +1512,7 @@ private void doFilenameSearch(String statement, List<ObjectData> list, Set<Strin
String filename = expr;
log.debug("filename: {}", filename);

DocumentDAO docDao = Context.get().getBean(DocumentDAO.class);
DocumentDAO docDao = Context.get(DocumentDAO.class);
List<Document> docs = docDao.findByFileNameAndParentFolderId(null, filename, null, getSessionUser().getId(),
maxItems);

Expand Down Expand Up @@ -1642,7 +1642,7 @@ private void checkPublished(User user, Document doc) throws PermissionException
}

private void checkReadEnable(User user, long folderId) throws PermissionException, PersistenceException {
FolderDAO dao = Context.get().getBean(FolderDAO.class);
FolderDAO dao = Context.get(FolderDAO.class);
if (!dao.isReadAllowed(folderId, user.getId())) {
String message = "User " + user.getUsername() + " doesn't have read permission on folder " + folderId;
log.error(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private static void addDocumentPropertyDefinitions(DocumentTypeDefinitionImpl ty
/*
* Extended properties
*/
AttributeSetDAO dao = Context.get().getBean(AttributeSetDAO.class);
AttributeSetDAO dao = Context.get(AttributeSetDAO.class);
List<AttributeSet> sets = dao.findAll();
for (AttributeSet set : sets) {
dao.initialize(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public int bulkUpdate(String expression, Map<String, Object> parameters) throws
}

protected Connection getConnection() throws PersistenceException {
DataSource dataSource = (DataSource) Context.get().getBean(DATA_SOURCE);
DataSource dataSource = (DataSource) Context.get(DATA_SOURCE);
try {
return dataSource.getConnection();
} catch (Exception e) {
Expand Down Expand Up @@ -645,7 +645,7 @@ protected int cleanOldRecords(int ttl, String tableName) throws PersistenceExcep
@Override
public Map<String, String> getDatabaseMetadata() {
Map<String, String> map = new HashMap<>();
DataSource dataSource = (DataSource) Context.get().getBean(DATA_SOURCE);
DataSource dataSource = (DataSource) Context.get(DATA_SOURCE);
try (Connection connection = dataSource.getConnection();) {
DatabaseMetaData meta = connection.getMetaData();
map.put("db.product.name", meta.getDatabaseProductName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ContextTool {
* @return the instance
*/
public Object getBean(String id) {
return Context.get().getBean(id);
return Context.get(id);
}

/**
Expand Down
Loading

0 comments on commit 2bd4458

Please sign in to comment.