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);
}
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;
}
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);
}
}
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);
}
}
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();
}
}
Aggregations