[DS-4287] Refactoring the IndexableObject & SolrServiceImpl: Additional comments, some more narrowing of generics, additional error catching & cleaner way to resolve permissions

This commit is contained in:
Kevin Van de Velde
2020-01-10 10:33:56 +01:00
parent 87515d6deb
commit 2c5ed44f81
11 changed files with 27 additions and 16 deletions

View File

@@ -29,6 +29,10 @@ public interface IndexableObject<T extends ReloadableEntity, PK extends Serializ
*/
String getType();
/**
* Return the identifier of this indexableObject, this will be the identifier of the object in the database
* @return for a DSpaceObject a uuid will be returned, for a tasks or workflow items an integer will be returned
*/
PK getID();
/**

View File

@@ -21,7 +21,7 @@ import org.dspace.discovery.indexobject.factory.DSpaceObjectIndexFactory;
* Factory implementation for indexing/retrieving DSpaceObjects in the search core
* @author Kevin Van de Velde (kevin at atmire dot com)
*/
public abstract class DSpaceObjectIndexFactoryImpl<T extends IndexableDSpaceObject, S>
public abstract class DSpaceObjectIndexFactoryImpl<T extends IndexableDSpaceObject, S extends DSpaceObject>
extends IndexFactoryImpl<T, S> implements DSpaceObjectIndexFactory<T, S> {
@Override

View File

@@ -190,7 +190,4 @@ public abstract class IndexFactoryImpl<T extends IndexableObject, S> implements
public void deleteAll() throws IOException, SolrServerException {
solrSearchCore.getSolr().deleteByQuery(SearchUtils.RESOURCE_TYPE_FIELD + ":" + getType());
}
@Override
public abstract List getIndexableObjects(Context context, S object) throws SQLException;
}

View File

@@ -26,8 +26,9 @@ import org.springframework.beans.factory.annotation.Autowired;
* Factory implementation for indexing/retrieving InProgressSubmissions in the search core
* @author Kevin Van de Velde (kevin at atmire dot com)
*/
public abstract class InprogressSubmissionIndexFactoryImpl<T extends IndexableInProgressSubmission, S>
extends IndexFactoryImpl<T, S> implements InprogressSubmissionIndexFactory<T, S> {
public abstract class InprogressSubmissionIndexFactoryImpl
<T extends IndexableInProgressSubmission, S extends InProgressSubmission> extends IndexFactoryImpl<T, S>
implements InprogressSubmissionIndexFactory<T, S> {
@Autowired
protected CollectionIndexFactory indexableCollectionService;

View File

@@ -41,6 +41,7 @@ import org.dspace.content.authority.service.MetadataAuthorityService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.discovery.FullTextContentStreams;
import org.dspace.discovery.IndexableObject;
import org.dspace.discovery.SearchUtils;
@@ -614,7 +615,8 @@ public class ItemIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Indexable
}
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error(LogManager.getHeader(context, "item_metadata_discovery_error",
"Item identifier: " + item.getID()), e);
}
@@ -636,7 +638,8 @@ public class ItemIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Indexable
}
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error(LogManager.getHeader(context, "item_publication_group_discovery_error",
"Item identifier: " + item.getID()), e);
}

View File

@@ -11,6 +11,7 @@ import java.sql.SQLException;
import java.util.List;
import org.apache.solr.common.SolrInputDocument;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.dspace.discovery.indexobject.IndexableDSpaceObject;
@@ -19,7 +20,8 @@ import org.dspace.discovery.indexobject.IndexableDSpaceObject;
*
* @author Kevin Van de Velde (kevin at atmire dot com)
*/
public interface DSpaceObjectIndexFactory<T extends IndexableDSpaceObject, S> extends IndexFactory<T, S> {
public interface DSpaceObjectIndexFactory<T extends IndexableDSpaceObject, S extends DSpaceObject>
extends IndexFactory<T, S> {
/**

View File

@@ -91,9 +91,9 @@ public interface IndexFactory<T extends IndexableObject, S> {
Optional<T> findIndexableObject(Context context, String id) throws SQLException;
/**
* Determine whether the class can handle the object
* @param object The object which should be handle
* @return True if the class can handle the given object. False if it doesn't.
* Determine whether the class can handle the factory implementation
* @param object The object which we want to check
* @return True if the factory implementation can handle the given object. False if it doesn't.
*/
boolean supports(Object object);

View File

@@ -19,7 +19,8 @@ import org.dspace.discovery.indexobject.IndexableInProgressSubmission;
*
* @author Kevin Van de Velde (kevin at atmire dot com)
*/
public interface InprogressSubmissionIndexFactory<T extends IndexableInProgressSubmission, S>
public interface InprogressSubmissionIndexFactory<T extends IndexableInProgressSubmission,
S extends InProgressSubmission>
extends IndexFactory<T, S> {
/**

View File

@@ -11,6 +11,7 @@ import java.io.Serializable;
import java.sql.SQLException;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.ClaimedTaskRest;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
@@ -49,7 +50,7 @@ public class ClaimedTaskRestPermissionEvaluatorPlugin extends RestObjectPermissi
public boolean hasDSpacePermission(Authentication authentication, Serializable targetId,
String targetType, DSpaceRestPermission permission) {
if (!StringUtils.equals("CLAIMEDTASK", targetType)) {
if (!StringUtils.equalsIgnoreCase(ClaimedTaskRest.NAME, targetType)) {
return false;
}

View File

@@ -12,6 +12,7 @@ import java.io.Serializable;
import java.sql.SQLException;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.PoolTaskRest;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
@@ -51,7 +52,7 @@ public class PoolTaskRestPermissionEvaluatorPlugin extends RestObjectPermissionE
public boolean hasDSpacePermission(Authentication authentication, Serializable targetId,
String targetType, DSpaceRestPermission permission) {
if (!StringUtils.equals("POOLTASK", targetType)) {
if (!StringUtils.equalsIgnoreCase(PoolTaskRest.NAME, targetType)) {
return false;
}

View File

@@ -12,6 +12,7 @@ import java.io.Serializable;
import java.sql.SQLException;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.WorkflowItemRest;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
@@ -62,7 +63,7 @@ public class WorkflowRestPermissionEvaluatorPlugin extends RestObjectPermissionE
//This plugin currently only evaluates READ access
DSpaceRestPermission restPermission = DSpaceRestPermission.convert(permission);
if (!DSpaceRestPermission.READ.equals(restPermission)
|| !StringUtils.equals(targetType, "WORKFLOWITEM")) {
|| !StringUtils.equals(WorkflowItemRest.NAME, targetType)) {
return false;
}