[CST-7756] monor fix

This commit is contained in:
Mykhaylo
2023-02-02 12:53:57 +01:00
parent 22ebb04fcd
commit de7d1738fc
4 changed files with 15 additions and 24 deletions

View File

@@ -17,7 +17,9 @@ import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.service.CollectionService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
@@ -49,7 +51,9 @@ public class SubscribeServiceImpl implements SubscribeService {
if (StringUtils.isBlank(resourceType)) {
return subscriptionDAO.findAllOrderedByDSO(context, limit, offset);
} else {
if (resourceType.equals("Item") || resourceType.equals("Collection") || resourceType.equals("Community")) {
if (resourceType.equals(Item.class.getSimpleName()) ||
resourceType.equals(Collection.class.getSimpleName()) ||
resourceType.equals(Community.class.getSimpleName())) {
return subscriptionDAO.findAllOrderedByIDAndResourceType(context, resourceType, limit, offset);
} else {
log.error("Resource type must be Item, Collection or Community");
@@ -71,7 +75,7 @@ public class SubscribeServiceImpl implements SubscribeService {
subscriptionParameterList.forEach(subscriptionParameter ->
newSubscription.addParameter(subscriptionParameter));
newSubscription.setEPerson(eperson);
newSubscription.setdSpaceObject(dSpaceObject);
newSubscription.setDSpaceObject(dSpaceObject);
newSubscription.setSubscriptionType(type);
return newSubscription;
} else {
@@ -154,7 +158,7 @@ public class SubscribeServiceImpl implements SubscribeService {
Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id);
subscriptionDB.removeParameterList();
subscriptionDB.setSubscriptionType(type);
subscriptionDB.setdSpaceObject(dSpaceObject);
subscriptionDB.setDSpaceObject(dSpaceObject);
subscriptionParameterList.forEach(x -> subscriptionDB.addParameter(x));
subscriptionDB.setEPerson(eperson);
subscriptionDAO.save(context, subscriptionDB);

View File

@@ -87,10 +87,6 @@ public class Subscription implements ReloadableEntity<Integer> {
this.ePerson = ePerson;
}
public void setdSpaceObject(DSpaceObject dSpaceObject) {
this.dSpaceObject = dSpaceObject;
}
public String getSubscriptionType() {
return subscriptionType;
}

View File

@@ -23,7 +23,10 @@ import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.discovery.IndexableObject;
import org.dspace.eperson.Subscription;
@@ -82,13 +85,14 @@ public class SubscriptionEmailNotificationServiceImpl implements SubscriptionEma
DSpaceObject dSpaceObject = subscription.getDSpaceObject();
if (dSpaceObject.getType() == COMMUNITY) {
communities.addAll(contentUpdates.get("community")
communities.addAll(contentUpdates.get(Community.class.getSimpleName())
.findUpdates(context, dSpaceObject, frequency));
} else if (dSpaceObject.getType() == COLLECTION) {
collections.addAll(contentUpdates.get("collection")
collections.addAll(contentUpdates.get(Collection.class.getSimpleName())
.findUpdates(context, dSpaceObject, frequency));
} else if (dSpaceObject.getType() == ITEM) {
items.addAll(contentUpdates.get("item").findUpdates(context, dSpaceObject, frequency));
items.addAll(contentUpdates.get(Item.class.getSimpleName())
.findUpdates(context, dSpaceObject, frequency));
}
var ePerson = subscription.getEPerson();

View File

@@ -15,13 +15,8 @@ import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.model.DSpaceObjectRest;
import org.dspace.app.rest.model.SubscriptionRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.eperson.Subscription;
import org.dspace.eperson.service.SubscribeService;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
@@ -45,15 +40,7 @@ public class SubscriptionDSpaceObjectLinkRepository extends AbstractDSpaceRestRe
if (Objects.isNull(subscription)) {
throw new ResourceNotFoundException("No such subscription: " + subscriptionId);
}
if (subscription.getDSpaceObject() instanceof Item ||
subscription.getDSpaceObject() instanceof Community ||
subscription.getDSpaceObject() instanceof Collection) {
return converter.toRest(subscription.getDSpaceObject(), projection);
} else {
HibernateProxy hibernateProxy = (HibernateProxy) subscription.getDSpaceObject();
LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer();
return converter.toRest(initializer.getImplementation(), projection);
}
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}