Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1822 (pull request DSpace#2453)
Browse files Browse the repository at this point in the history
DSC-1822

Approved-by: Giuseppe Digilio
  • Loading branch information
vins01-4science authored and atarix83 committed Jul 16, 2024
2 parents 451e066 + 9e419c5 commit 190ac38
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.DSpaceCommandLineParameter;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -31,7 +33,7 @@ public class BulkImportScriptConfiguration<T extends BulkImport> extends ScriptC
private Class<T> dspaceRunnableClass;

@Override
public boolean isAllowedToExecute(Context context) {
public boolean isAllowedToExecute(Context context, List<DSpaceCommandLineParameter> commandLineParameters) {
try {
return authorizeService.isCollectionAdmin(context) || authorizeService.isAdmin(context);
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
package org.dspace.app.bulkedit;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.DSpaceCommandLineParameter;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -30,7 +32,7 @@ public class CollectionExportScriptConfiguration<T extends CollectionExport> ext
private Class<T> dspaceRunnableClass;

@Override
public boolean isAllowedToExecute(Context context) {
public boolean isAllowedToExecute(Context context, List<DSpaceCommandLineParameter> commandLineParameters) {
try {
return authorizeService.isCollectionAdmin(context) || authorizeService.isAdmin(context);
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@

package org.dspace.app.bulkedit;

import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.core.exception.SQLRuntimeException;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

/**
* The {@link ScriptConfiguration} for the {@link MetadataExportSearch} script
*/
public class MetadataExportSearchScriptConfiguration<T extends MetadataExportSearch> extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableclass;

@Override
Expand All @@ -37,15 +28,6 @@ public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) {
this.dspaceRunnableclass = dspaceRunnableClass;
}

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
*/
package org.dspace.app.metadata.export;

import java.sql.SQLException;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Configuration of the Script {@code MetadataSchemaExportScript}
Expand All @@ -24,9 +19,6 @@
public class MetadataSchemaExportScriptConfiguration<T extends MetadataSchemaExportScript>
extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableClass;

@Override
Expand All @@ -39,14 +31,6 @@ public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) {
this.dspaceRunnableClass = dspaceRunnableClass;
}

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}

@Override
public Options getOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
package org.dspace.app.nbevent;

import java.io.InputStream;
import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

public class NBEventsScriptConfiguration<T extends NBEventsRunnable> extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableClass;

@Override
Expand All @@ -37,15 +30,6 @@ public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) {
this.dspaceRunnableClass = dspaceRunnableClass;
}

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@
*/
package org.dspace.app.suggestion;

import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

public class OAIREPublicationLoaderScriptConfiguration<T extends OAIREPublicationLoaderRunnable>
extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableClass;

@Override
Expand All @@ -37,14 +29,6 @@ public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) {
this.dspaceRunnableClass = dspaceRunnableClass;
}

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}

@Override
public Options getOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
* http://www.dspace.org/license/
*/
package org.dspace.authority.script;
import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
* {@link ScriptConfiguration} for the {@link UpdateItemReference}.
Expand All @@ -28,19 +24,6 @@ public class UpdateItemReferenceScriptConfiguration<T extends UpdateItemReferenc

private Class<T> dspaceRunnableClass;

@Autowired
private AuthorizeService authorizeService;

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
return false;
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
*/
package org.dspace.content.enhancer.script;

import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Script configuration of {@link ItemEnhancerScript}.
Expand All @@ -22,20 +17,8 @@
*/
public class ItemEnhancerScriptConfiguration<T extends ItemEnhancerScript> extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableClass;

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public class BulkItemExportScriptConfiguration<T extends BulkItemExport> extends

@Override
public boolean isAllowedToExecute(Context context, List<DSpaceCommandLineParameter> commandLineParameters) {
return this.isAllowedToExecute(context);
}

@Override
public boolean isAllowedToExecute(Context context) {
StringBuilder property = new StringBuilder("bulk-export.limit.");
AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
ConfigurationService configurationService = new DSpace().getConfigurationService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public class ItemExportScriptConfiguration<T extends ItemExport> extends ScriptC

@Override
public boolean isAllowedToExecute(Context context, List<DSpaceCommandLineParameter> commandLineParameters) {
return this.isAllowedToExecute(context);
}

@Override
public boolean isAllowedToExecute(Context context) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
package org.dspace.layout.script;

import java.io.InputStream;
import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Configuration for {@link CrisLayoutToolScript}.
Expand All @@ -23,20 +19,8 @@
*/
public class CrisLayoutToolScriptConfiguration<T extends CrisLayoutToolScript> extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableClass;

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
*/
package org.dspace.layout.script;

import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Configuration for {@link ExportCrisLayoutToolScript}.
Expand All @@ -23,20 +18,8 @@
public class ExportCrisLayoutToolScriptConfiguration<T extends ExportCrisLayoutToolScript>
extends ScriptConfiguration<T> {

@Autowired
private AuthorizeService authorizeService;

private Class<T> dspaceRunnableClass;

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e);
}
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
*/
package org.dspace.metrics;

import java.sql.SQLException;

import org.apache.commons.cli.Options;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.scripts.configuration.ScriptConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
* {@link ScriptConfiguration} for the {@link StoreViewDownloadsCrisMetrics}.
Expand All @@ -31,19 +26,6 @@ public class StoreViewDownloadsCrisMetricsScriptConfiguration<T extends StoreVie

private Class<T> dspaceRunnableClass;

@Autowired
private AuthorizeService authorizeService;

@Override
public boolean isAllowedToExecute(Context context) {
try {
return authorizeService.isAdmin(context);
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
return false;
}

@Override
public Options getOptions() {
if (options == null) {
Expand Down
Loading

0 comments on commit 190ac38

Please sign in to comment.