Search in sources :

Example 1 with WorkflowItem

use of org.dspace.workflow.WorkflowItem in project DSpace by DSpace.

the class InprogressSubmissionIndexFactoryImpl method storeInprogressItemFields.

@Override
public void storeInprogressItemFields(Context context, SolrInputDocument doc, InProgressSubmission inProgressSubmission) throws SQLException, IOException {
    final Item item = inProgressSubmission.getItem();
    doc.addField("lastModified", SolrUtils.getDateFormatter().format(item.getLastModified()));
    EPerson submitter = inProgressSubmission.getSubmitter();
    if (submitter != null) {
        addFacetIndex(doc, "submitter", submitter.getID().toString(), submitter.getFullName());
    }
    doc.addField("inprogress.item", new IndexableItem(inProgressSubmission.getItem()).getUniqueIndexID());
    // get the location string (for searching by collection & community)
    List<String> locations = indexableCollectionService.getCollectionLocations(context, inProgressSubmission.getCollection());
    // add the item's owning collection to the location list
    // NOTE: inProgressSubmission.getItem().getCollections() is empty while the item is in-progress.
    locations.add("l" + inProgressSubmission.getCollection().getID());
    // Add item metadata
    List<DiscoveryConfiguration> discoveryConfigurations;
    if (inProgressSubmission instanceof WorkflowItem) {
        discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations((WorkflowItem) inProgressSubmission);
    } else if (inProgressSubmission instanceof WorkspaceItem) {
        discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations((WorkspaceItem) inProgressSubmission);
    } else {
        discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(item);
    }
    indexableItemService.addDiscoveryFields(doc, context, item, discoveryConfigurations);
    indexableCollectionService.storeCommunityCollectionLocations(doc, locations);
}
Also used : Item(org.dspace.content.Item) WorkflowItem(org.dspace.workflow.WorkflowItem) WorkspaceItem(org.dspace.content.WorkspaceItem) WorkflowItem(org.dspace.workflow.WorkflowItem) DiscoveryConfiguration(org.dspace.discovery.configuration.DiscoveryConfiguration) EPerson(org.dspace.eperson.EPerson) WorkspaceItem(org.dspace.content.WorkspaceItem)

Example 2 with WorkflowItem

use of org.dspace.workflow.WorkflowItem in project DSpace by DSpace.

the class EZIDIdentifierProviderTest method newItem.

/**
 * Create a fresh Item, installed in the repository.
 *
 * @throws SQLException       if database error
 * @throws AuthorizeException if authorization error
 * @throws IOException        if IO error
 */
private Item newItem() throws SQLException, AuthorizeException, IOException, WorkflowException {
    // Install a fresh item
    context.turnOffAuthorisationSystem();
    WorkspaceItem wsItem = workspaceItemService.create(context, collection, false);
    WorkflowItem wfItem = WorkflowServiceFactory.getInstance().getWorkflowService().start(context, wsItem);
    item = wfItem.getItem();
    itemService.addMetadata(context, item, "dc", "contributor", "author", null, "Author, A. N.");
    itemService.addMetadata(context, item, "dc", "title", null, null, "A Test Object");
    itemService.addMetadata(context, item, "dc", "publisher", null, null, "DSpace Test Harness");
    itemService.update(context, item);
    // Commit work, clean up
    context.restoreAuthSystemState();
    return item;
}
Also used : WorkflowItem(org.dspace.workflow.WorkflowItem) WorkspaceItem(org.dspace.content.WorkspaceItem)

Example 3 with WorkflowItem

use of org.dspace.workflow.WorkflowItem in project DSpace by DSpace.

the class ContainerManagerDSpace method doContainerDelete.

protected void doContainerDelete(SwordContext swordContext, Item item, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig) throws DSpaceSwordException, SwordAuthException {
    try {
        Context context = swordContext.getContext();
        // first figure out if there's anything we need to do about the workflow/workspace state
        WorkflowTools wft = new WorkflowTools();
        if (wft.isItemInWorkspace(swordContext.getContext(), item)) {
            WorkspaceItem wsi = wft.getWorkspaceItem(context, item);
            workspaceItemService.deleteAll(context, wsi);
        } else if (wft.isItemInWorkflow(context, item)) {
            WorkflowItem wfi = wft.getWorkflowItem(context, item);
            workflowItemService.deleteWrapper(context, wfi);
        }
        // then delete the item
        itemService.delete(context, item);
    } catch (SQLException | IOException e) {
        throw new DSpaceSwordException(e);
    } catch (AuthorizeException e) {
        throw new SwordAuthException(e);
    }
}
Also used : Context(org.dspace.core.Context) SQLException(java.sql.SQLException) AuthorizeException(org.dspace.authorize.AuthorizeException) WorkflowItem(org.dspace.workflow.WorkflowItem) IOException(java.io.IOException) SwordAuthException(org.swordapp.server.SwordAuthException) WorkspaceItem(org.dspace.content.WorkspaceItem)

Example 4 with WorkflowItem

use of org.dspace.workflow.WorkflowItem in project DSpace by DSpace.

the class CollectionListManagerDSpace method listItems.

private List<Item> listItems(SwordContext sc, Collection collection, SwordConfiguration swordConfig) throws DSpaceSwordException {
    try {
        EPerson person = sc.getOnBehalfOf() != null ? sc.getOnBehalfOf() : sc.getAuthenticated();
        List<Item> collectionItems = new ArrayList<>();
        // first get the ones out of the archive
        Iterator<Item> items = itemService.findBySubmitter(sc.getContext(), person);
        while (items.hasNext()) {
            Item item = items.next();
            List<Collection> cols = item.getCollections();
            for (Collection col : cols) {
                if (col.getID().equals(collection.getID())) {
                    collectionItems.add(item);
                    break;
                }
            }
        }
        // now get the ones out of the workspace
        List<WorkspaceItem> wsis = workspaceItemService.findByEPerson(sc.getContext(), person);
        for (WorkspaceItem wsi : wsis) {
            Item item = wsi.getItem();
            // check for the wsi collection
            Collection wsCol = wsi.getCollection();
            if (wsCol.getID().equals(collection.getID())) {
                collectionItems.add(item);
            }
            // then see if there are any additional associated collections
            List<Collection> cols = item.getCollections();
            for (Collection col : cols) {
                if (col.getID().equals(collection.getID())) {
                    collectionItems.add(item);
                    break;
                }
            }
        }
        // finally get the ones out of the workflow
        List wfis = workflowItemService.findBySubmitter(sc.getContext(), person);
        for (Object found : wfis) {
            if (found instanceof WorkflowItem) {
                WorkflowItem wfi = (WorkflowItem) found;
                Item item = wfi.getItem();
                // check for the wfi collection
                Collection wfCol = wfi.getCollection();
                if (wfCol.getID().equals(collection.getID())) {
                    collectionItems.add(item);
                }
                // then see if there are any additional associated collections
                List<Collection> cols = item.getCollections();
                for (Collection col : cols) {
                    if (col.getID().equals(collection.getID())) {
                        collectionItems.add(item);
                        break;
                    }
                }
            }
        }
        return collectionItems;
    } catch (SQLException e) {
        throw new DSpaceSwordException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) EPerson(org.dspace.eperson.EPerson) Item(org.dspace.content.Item) WorkspaceItem(org.dspace.content.WorkspaceItem) WorkflowItem(org.dspace.workflow.WorkflowItem) WorkflowItem(org.dspace.workflow.WorkflowItem) Collection(org.dspace.content.Collection) ArrayList(java.util.ArrayList) List(java.util.List) WorkspaceItem(org.dspace.content.WorkspaceItem)

Example 5 with WorkflowItem

use of org.dspace.workflow.WorkflowItem in project DSpace by DSpace.

the class RestartWorkflow method main.

public static void main(String[] args) {
    try {
        System.out.println("All workflowitems will be sent back to the first workflow step.");
        Context context = new Context();
        context.turnOffAuthorisationSystem();
        // create an options object and populate it
        CommandLineParser parser = new DefaultParser();
        Options options = new Options();
        options.addOption("e", "eperson", true, "email of eperson doing importing");
        options.addOption("n", "notify", false, "if sending submissions through the workflow, send notification emails");
        options.addOption("p", "provenance", true, "the provenance description to be added to the item");
        options.addOption("h", "help", false, "help");
        CommandLine line = parser.parse(options, args);
        // db ID or email
        String eperson = null;
        if (line.hasOption('h')) {
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("RestartWorkflow\n", options);
            System.exit(0);
        }
        if (line.hasOption('n')) {
            useWorkflowSendEmail = true;
        }
        // eperson
        if (line.hasOption('e')) {
            eperson = line.getOptionValue('e');
        } else {
            System.out.println("The -e (eperson) option is mandatory !");
            System.exit(1);
        }
        // find the EPerson, assign to context
        EPerson myEPerson = null;
        if (eperson.indexOf('@') != -1) {
            // @ sign, must be an email
            myEPerson = ePersonService.findByEmail(context, eperson);
        } else {
            myEPerson = ePersonService.find(context, UUID.fromString(eperson));
        }
        if (myEPerson == null) {
            System.out.println("Error, eperson cannot be found: " + eperson);
            System.exit(1);
        }
        String provenance = null;
        if (line.hasOption('p')) {
            provenance = line.getOptionValue('p');
        }
        context.setCurrentUser(myEPerson);
        System.out.println("Sending all workflow items back to the workspace");
        WorkflowServiceFactory workflowServiceFactory = WorkflowServiceFactory.getInstance();
        List<WorkflowItem> workflowItems = workflowServiceFactory.getWorkflowItemService().findAll(context);
        WorkflowService workflowService = workflowServiceFactory.getWorkflowService();
        int i = 0;
        for (WorkflowItem workflowItem : workflowItems) {
            System.out.println("Processing workflow item " + i + " of " + workflowItems.size());
            System.out.println("Removing pooled tasks");
            // rejection provenance
            Item myitem = workflowItem.getItem();
            // Get current date
            // String now = DCDate.getCurrent().toString();
            // Add to item as a DC field
            // TaskLog tasklog = TaskLog.create(c, wi);
            // tasklog.update();
            // convert into personal workspace
            WorkspaceItem wsi = workflowService.sendWorkflowItemBackSubmission(context, workflowItem, myEPerson, provenance, "");
            log.info(LogHelper.getHeader(context, "restart_workflow", "workflow_item_id=" + workflowItem.getID() + "item_id=" + workflowItem.getItem().getID() + "collection_id=" + workflowItem.getCollection().getID()));
            if (useWorkflowSendEmail) {
                workflowService.start(context, wsi);
            } else {
                workflowService.startWithoutNotify(context, wsi);
            }
            i++;
        }
        System.out.println("All done, committing context");
        context.complete();
        System.exit(0);
    } catch (Exception e) {
        log.error("Error while sending all workflow items back to the workspace", e);
        e.printStackTrace();
    }
}
Also used : Context(org.dspace.core.Context) Options(org.apache.commons.cli.Options) EPerson(org.dspace.eperson.EPerson) HelpFormatter(org.apache.commons.cli.HelpFormatter) WorkflowServiceFactory(org.dspace.workflow.factory.WorkflowServiceFactory) Item(org.dspace.content.Item) WorkflowItem(org.dspace.workflow.WorkflowItem) WorkspaceItem(org.dspace.content.WorkspaceItem) CommandLine(org.apache.commons.cli.CommandLine) WorkflowService(org.dspace.workflow.WorkflowService) WorkflowItem(org.dspace.workflow.WorkflowItem) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser) WorkspaceItem(org.dspace.content.WorkspaceItem)

Aggregations

WorkspaceItem (org.dspace.content.WorkspaceItem)16 WorkflowItem (org.dspace.workflow.WorkflowItem)16 Item (org.dspace.content.Item)11 SQLException (java.sql.SQLException)7 AuthorizeException (org.dspace.authorize.AuthorizeException)5 Collection (org.dspace.content.Collection)5 Context (org.dspace.core.Context)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 EPerson (org.dspace.eperson.EPerson)4 Test (org.junit.Test)4 AbstractControllerIntegrationTest (org.dspace.app.rest.test.AbstractControllerIntegrationTest)3 Community (org.dspace.content.Community)3 Version (org.dspace.versioning.Version)3 VersionHistory (org.dspace.versioning.VersionHistory)3 ItemRest (org.dspace.app.rest.model.ItemRest)2 WorkflowService (org.dspace.workflow.WorkflowService)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 FileNotFoundException (java.io.FileNotFoundException)1 List (java.util.List)1