* details.
*/
public static void main(String[] args)
{
log.info("#### START DELETE: -----" + new Date() + " ----- ####");
Context dspaceContext = null;
ApplicationContext context = null;
try
{
dspaceContext = new Context();
dspaceContext.turnOffAuthorisationSystem();
DSpace dspace = new DSpace();
ApplicationService applicationService = dspace.getServiceManager().getServiceByName(
"applicationService", ApplicationService.class);
CommandLineParser parser = new PosixParser();
Options options = new Options();
options.addOption("h", "help", false, "help");
options.addOption("r", "researcher", true, "RP id to delete");
options.addOption("s", "silent", false, "no interactive mode");
CommandLine line = parser.parse(options, args);
if (line.hasOption('h'))
{
HelpFormatter myhelp = new HelpFormatter();
myhelp.printHelp("ScriptHKURPDelete \n", options);
System.out.println("\n\nUSAGE:\n ScriptHKURPDelete -r <id> \n");
System.out
.println("Please note: add -s for no interactive mode");
System.exit(0);
}
Integer rpId = null;
boolean delete = false;
boolean silent = line.hasOption('s');
Item[] items = null;
if (line.hasOption('r'))
{
rpId = ResearcherPageUtils.getRealPersistentIdentifier(line.getOptionValue("r"),ResearcherPage.class);
ResearcherPage rp = applicationService.get(
ResearcherPage.class, rpId);
if (rp == null)
{
if (!silent)
{
System.out.println("RP not exist...exit");
}
log.info("RP not exist...exit");
System.exit(0);
}
log.info("Use browse indexing");
BrowseIndex bi = BrowseIndex.getBrowseIndex(plugInBrowserIndex);
// now start up a browse engine and get it to do the work for us
BrowseEngine be = new BrowseEngine(dspaceContext);
String authKey = ResearcherPageUtils.getPersistentIdentifier(rp);
// set up a BrowseScope and start loading the values into it
BrowserScope scope = new BrowserScope(dspaceContext);
scope.setBrowseIndex(bi);
// scope.setOrder(order);
scope.setFilterValue(authKey);
scope.setAuthorityValue(authKey);
scope.setResultsPerPage(Integer.MAX_VALUE);
scope.setBrowseLevel(1);
BrowseInfo binfo = be.browse(scope);
log.debug("Find " + binfo.getResultCount()
+ "item(s) for the reseracher " + authKey);
items = binfo.getItemResults(dspaceContext);
if (!silent && rp != null)
{
System.out.println(MESSAGE_ONE);
// interactive mode
System.out.println("Attempting to remove Researcher Page:");
System.out.println("StaffNo:" + rp.getSourceID());
System.out.println("FullName:" + rp.getFullName());
System.out.println("the researcher has " + items.length + " relation(s) with item(s) in the HUB");
System.out.println();
System.out.println(QUESTION_ONE);
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(isr);
String answer = reader.readLine();
if (answer.equals("yes"))
{
delete = true;
}
else
{
System.out.println("Exit without delete");
log.info("Exit without delete");
System.exit(0);
}
}
else
{
delete = true;
}
}
else
{
System.out
.println("\n\nUSAGE:\n ScriptHKURPDelete <-v> -r <RPid> \n");
System.out.println("-r option is mandatory");
log.error("-r option is mandatory");
System.exit(1);
}
if (delete)
{
if (!silent)
{
System.out.println("Deleting...");
}
log.info("Deleting...");
cleanAuthority(dspaceContext, items, rpId);
applicationService.delete(ResearcherPage.class, rpId);
dspaceContext.complete();
}
if (!silent)
{
System.out.println("Ok...Bye");
}
}
catch (Exception e)
{
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
finally
{
if (dspaceContext != null && dspaceContext.isValid())
{
dspaceContext.abort();
}
if (context != null)
{
context.publishEvent(new ContextClosedEvent(context));
}