From f748ff539fa89f7b144f8fb7d3d283e3247a6e62 Mon Sep 17 00:00:00 2001 From: Sascha Szott Date: Wed, 26 Jul 2023 11:26:01 +0200 Subject: [PATCH] remove package org.dspace.subscriptions.dSpaceObjectsUpdates --- .../CollectionsUpdates.java | 47 ---- .../CommunityUpdates.java | 48 ----- .../dSpaceObjectsUpdates/ItemsUpdates.java | 200 ------------------ 3 files changed, 295 deletions(-) delete mode 100644 dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CollectionsUpdates.java delete mode 100644 dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CommunityUpdates.java delete mode 100644 dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/ItemsUpdates.java diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CollectionsUpdates.java b/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CollectionsUpdates.java deleted file mode 100644 index 4e621eb7e057..000000000000 --- a/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CollectionsUpdates.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE and NOTICE files at the root of the source - * tree and available online at - * - * http://www.dspace.org/license/ - */ - -package org.dspace.subscriptions.dSpaceObjectsUpdates; - -import java.util.List; - -import org.dspace.content.DSpaceObject; -import org.dspace.content.Item; -import org.dspace.core.Context; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.IndexableObject; -import org.dspace.discovery.SearchService; -import org.dspace.discovery.SearchServiceException; -import org.dspace.subscriptions.service.DSpaceObjectUpdates; - - -/** - * Class which will be used to find - * all collection objects updated related with subscribed DSO - * - * @author Alba Aliu - */ -public class CollectionsUpdates implements DSpaceObjectUpdates { - private final SearchService searchService; - - @Override - public List findUpdates(Context context, DSpaceObject dSpaceObject, String frequency) - throws SearchServiceException { - DiscoverQuery discoverQuery = new DiscoverQuery(); - discoverQuery.addFilterQueries("search.resourcetype:" + Item.class.getSimpleName()); - discoverQuery.addFilterQueries("location.coll:(" + dSpaceObject.getID() + ")"); - discoverQuery.addFilterQueries("lastModified_dt:" + findLastFrequency(frequency)); - DiscoverResult discoverResult = searchService.search(context, discoverQuery); - return discoverResult.getIndexableObjects(); - } - - public CollectionsUpdates(SearchService searchService) { - this.searchService = searchService; - } -} diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CommunityUpdates.java b/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CommunityUpdates.java deleted file mode 100644 index b80860a3c76f..000000000000 --- a/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/CommunityUpdates.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE and NOTICE files at the root of the source - * tree and available online at - * - * http://www.dspace.org/license/ - */ - -package org.dspace.subscriptions.dSpaceObjectsUpdates; - -import java.util.List; - -import org.dspace.content.DSpaceObject; -import org.dspace.content.Item; -import org.dspace.core.Context; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.IndexableObject; -import org.dspace.discovery.SearchService; -import org.dspace.discovery.SearchServiceException; -import org.dspace.subscriptions.service.DSpaceObjectUpdates; - - - -/** - * Class which will be used to find - * all community objects updated related with subscribed DSO - * - * @author Alba Aliu - */ -public class CommunityUpdates implements DSpaceObjectUpdates { - private SearchService searchService; - - @Override - public List findUpdates(Context context, DSpaceObject dSpaceObject, String frequency) - throws SearchServiceException { - DiscoverQuery discoverQuery = new DiscoverQuery(); - discoverQuery.addFilterQueries("search.resourcetype:" + Item.class.getSimpleName()); - discoverQuery.addFilterQueries("location.comm:(" + dSpaceObject.getID() + ")"); - discoverQuery.addFilterQueries("lastModified_dt:" + this.findLastFrequency(frequency)); - DiscoverResult discoverResult = searchService.search(context, discoverQuery); - return discoverResult.getIndexableObjects(); - } - - public CommunityUpdates(SearchService searchService) { - this.searchService = searchService; - } -} diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/ItemsUpdates.java b/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/ItemsUpdates.java deleted file mode 100644 index bf0c1ab28e93..000000000000 --- a/dspace-api/src/main/java/org/dspace/subscriptions/dSpaceObjectsUpdates/ItemsUpdates.java +++ /dev/null @@ -1,200 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE and NOTICE files at the root of the source - * tree and available online at - * - * http://www.dspace.org/license/ - */ - -package org.dspace.subscriptions.dSpaceObjectsUpdates; - -import static org.apache.commons.lang3.StringUtils.trimToEmpty; - -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.Logger; -import org.dspace.content.DSpaceObject; -import org.dspace.content.Item; -import org.dspace.content.service.CollectionService; -import org.dspace.content.service.CommunityService; -import org.dspace.content.service.ItemService; -import org.dspace.core.Context; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.IndexableObject; -import org.dspace.discovery.SearchService; -import org.dspace.discovery.configuration.DiscoveryConfiguration; -import org.dspace.discovery.configuration.DiscoveryConfigurationService; -import org.dspace.discovery.configuration.DiscoveryRelatedItemConfiguration; -import org.dspace.discovery.configuration.DiscoverySortConfiguration; -import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration; -import org.dspace.discovery.configuration.DiscoverySortFunctionConfiguration; -import org.dspace.discovery.indexobject.IndexableCollection; -import org.dspace.discovery.indexobject.IndexableCommunity; -import org.dspace.discovery.indexobject.IndexableItem; -import org.dspace.subscriptions.ContentGenerator; -import org.dspace.subscriptions.service.DSpaceObjectUpdates; - - -/** - * Class which will be used to find - * all item objects updated related with subscribed DSO - * - * @author Alba Aliu - */ -public class ItemsUpdates implements DSpaceObjectUpdates { - private final CollectionService collectionService; - private final CommunityService communityService; - private final ItemService itemService; - private DiscoveryConfigurationService searchConfigurationService; - private SearchService searchService; - private final Logger log = org.apache.logging.log4j.LogManager.getLogger(ContentGenerator.class); - - - @Override - public List findUpdates(Context context, DSpaceObject dSpaceObject, String frequency) { - List list = new ArrayList<>(); - // entity type found - String inverseRelationName = "RELATION." + itemService.getEntityTypeLabel((Item) dSpaceObject); - List discoveryConfigurationList = - searchConfigurationService.getDiscoveryConfigurationWithPrefixName(inverseRelationName); - DiscoverQuery discoverQuery = null; - DiscoverResult searchResult = null; - IndexableObject indexableObject = resolveScope(context, dSpaceObject.getID().toString()); - try { - for (DiscoveryConfiguration discoveryConfiguration : discoveryConfigurationList) { - discoverQuery = buildDiscoveryQuery(discoveryConfiguration, indexableObject); - discoverQuery.addFilterQueries("lastModified_dt:" + this.findLastFrequency(frequency)); - searchResult = searchService.search(context, discoverQuery); - list.addAll(searchResult.getIndexableObjects()); - } - } catch (Exception e) { - log.error(e); - } - return list; - } - - private IndexableObject resolveScope(Context context, String scope) { - IndexableObject scopeObj = null; - if (StringUtils.isBlank(scope)) { - return scopeObj; - } - try { - UUID uuid = UUID.fromString(scope); - scopeObj = new IndexableCommunity(communityService.find(context, uuid)); - if (scopeObj.getIndexedObject() == null) { - scopeObj = new IndexableCollection(collectionService.find(context, uuid)); - } - if (scopeObj.getIndexedObject() == null) { - scopeObj = new IndexableItem(itemService.find(context, uuid)); - } - - } catch (IllegalArgumentException ex) { - String message = "The given scope string " + trimToEmpty(scope) + " is not a UUID"; - log.error(message); - } catch (SQLException ex) { - String message = "Unable to retrieve DSpace Object with ID " + trimToEmpty(scope) + " from the database"; - log.error(message); - } - - return scopeObj; - } - - private DiscoverQuery buildDiscoveryQuery(DiscoveryConfiguration discoveryConfiguration, - IndexableObject scope) throws SQLException { - - DiscoverQuery discoverQuery = buildBaseQuery(discoveryConfiguration, scope); - discoverQuery.addDSpaceObjectFilter(IndexableItem.TYPE); - configureSorting(discoverQuery, discoveryConfiguration.getSearchSortConfiguration(), scope); - return discoverQuery; - } - - - private void configureSorting(DiscoverQuery queryArgs, - DiscoverySortConfiguration searchSortConfiguration, - final IndexableObject scope) { - String sortBy = getDefaultSortField(searchSortConfiguration); - String sortOrder = getDefaultSortDirection(searchSortConfiguration); - //Update Discovery query - DiscoverySortFieldConfiguration sortFieldConfiguration = searchSortConfiguration - .getSortFieldConfiguration(sortBy); - - if (sortFieldConfiguration != null) { - String sortField; - - if (DiscoverySortFunctionConfiguration.SORT_FUNCTION.equals(sortFieldConfiguration.getType())) { - sortField = MessageFormat.format( - ((DiscoverySortFunctionConfiguration) sortFieldConfiguration).getFunction(scope.getID()), - scope.getID()); - } else { - sortField = searchService - .toSortFieldIndex( - sortFieldConfiguration.getMetadataField(), sortFieldConfiguration.getType()); - } - - - if ("asc".equalsIgnoreCase(sortOrder)) { - queryArgs.setSortField(sortField, DiscoverQuery.SORT_ORDER.asc); - } else if ("desc".equalsIgnoreCase(sortOrder)) { - queryArgs.setSortField(sortField, DiscoverQuery.SORT_ORDER.desc); - } else { - log.error(sortOrder + " is not a valid sort order"); - } - - } else { - log.error(sortBy + " is not a valid sort field"); - } - } - - private String getDefaultSortDirection(DiscoverySortConfiguration searchSortConfiguration) { - return searchSortConfiguration.getSortFields().iterator().next().getDefaultSortOrder().toString(); - } - - private String getDefaultSortField(DiscoverySortConfiguration searchSortConfiguration) { - String sortBy;// Attempt to find the default one, if none found we use SCORE - sortBy = "score"; - if (Objects.nonNull(searchSortConfiguration.getSortFields()) && - !searchSortConfiguration.getSortFields().isEmpty()) { - DiscoverySortFieldConfiguration defaultSort = searchSortConfiguration.getSortFields().get(0); - if (org.apache.commons.lang.StringUtils.isBlank(defaultSort.getMetadataField())) { - return sortBy; - } - sortBy = defaultSort.getMetadataField(); - } - return sortBy; - } - - private DiscoverQuery buildBaseQuery(DiscoveryConfiguration discoveryConfiguration, IndexableObject scope) { - DiscoverQuery discoverQuery = new DiscoverQuery(); - if (discoveryConfiguration == null) { - return discoverQuery; - } - discoverQuery.setDiscoveryConfigurationName(discoveryConfiguration.getId()); - List filterQueries = discoveryConfiguration.getDefaultFilterQueries(); - - for (String filterQuery : filterQueries) { - if (discoveryConfiguration instanceof DiscoveryRelatedItemConfiguration) { - discoverQuery.addFilterQueries(MessageFormat.format(filterQuery, scope.getID())); - } else { - discoverQuery.addFilterQueries(filterQuery); - } - } - - return discoverQuery; - } - - public ItemsUpdates(CollectionService collectionService, CommunityService communityService, ItemService itemService, - DiscoveryConfigurationService searchConfigurationService, SearchService searchService) { - this.collectionService = collectionService; - this.communityService = communityService; - this.itemService = itemService; - this.searchConfigurationService = searchConfigurationService; - this.searchService = searchService; - } -}