/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ package com.pcbsys.nirvana.apps; import com.pcbsys.nirvana.client.*; /** * Deletes a data group */ public class deleteDataGroup extends nSampleApp { private static deleteDataGroup mySelf = null; /** * This method demonstrates the Nirvana API calls necessary to delete * a data group. * It is called after all command line arguments have been received and * validated * * @param realmDetails a String[] containing the possible RNAME values * @param dataGroup the data group names to delete */ private void doit(String[] realmDetails, String dataGroup, int deleteType) { mySelf.constructSession(realmDetails); //Deletes the specified data groups try { //Get all data groups so we can delete the wanted group nDataGroup[] dataGrps = mySession.getDataGroups(); if (deleteType == 1) { //Delete the data groups specified mySession.deleteDataGroup(dataGroup); System.out.println("Successfully deleted group " + dataGroup); } else if (deleteType == 2) { //Iterate through the array and find our data group nDataGroup group = null; for (nDataGroup grp : dataGrps) { if (grp.getName().equals(dataGroup)) { group = grp; break; } } //Check we have the group if (group == null) { System.out.println("Unable to find the data group you wish to delete, please check name."); } else { //Delete the data group mySession.deleteDataGroup(group); System.out.println("Successfully deleted group " + dataGroup); } } } catch (nSecurityException e) { System.out.println("Insufficient permissions for the requested operation."); System.out.println("Please check the ACL settings on the server."); e.printStackTrace(); System.exit(1); } catch (nSessionNotConnectedException snce) { System.out.println("The session object used is not physically connected to the Nirvana realm."); System.out.println("Please ensure the realm is up and check your RNAME value."); snce.printStackTrace(); System.exit(1); } catch (nUnexpectedResponseException ure) { System.out.println("The Nirvana REALM has returned an unexpected response."); System.out.println("Please ensure the Nirvana REALM and client API used are compatible."); ure.printStackTrace(); System.exit(1); } catch (nRequestTimedOutException rtoe) { System.out.println("The requested operation has timed out waiting for a response from the REALM."); System.out.println("If this is a very busy REALM ask your administrator to increase the client timeout values."); rtoe.printStackTrace(); System.exit(1); } catch (nSessionPausedException e) { System.out.println("Session has been paused, please resume the session"); e.printStackTrace(); System.exit(1); } catch (nIllegalArgumentException e) { System.out.println("Illegal argument"); e.printStackTrace(); System.exit(1); } finally { //Close the session we opened try { nSessionFactory.close(mySession); } catch (Exception ex) { } //Close any other sessions within this JVM so that we can exit nSessionFactory.shutdown(); } } protected void processArgs(String[] args) { switch (args.length) { case 2: { System.getProperties().put("DeleteType", args[1]); } case 1: { if (args[0].equals("-?")) { Usage(); UsageEnv(); } System.getProperties().put("DataGroupName", args[0]); break; } default: { Usage(); } } } public static void main(String[] args) { //Create an instance for this class mySelf = new deleteDataGroup(); //Process command line arguments mySelf.processArgs(args); //Process Environment Variables nSampleApp.processEnvironmentVariables(); //Check the data group name specified String dataGroupName = System.getProperty("DataGroupName"); String deleteTypeStr = System.getProperty("DeleteType"); if (dataGroupName == null || dataGroupName.length() < 1 || deleteTypeStr == null || deleteTypeStr.length() < 1) { Usage(); System.exit(1); } int deleteType = Integer.parseInt(deleteTypeStr); if (deleteType != 1 && deleteType != 2) { Usage(); System.exit(1); } //Check the local realm details int idx = 0; String RNAME = null; if (System.getProperty("RNAME") != null) { RNAME = System.getProperty("RNAME"); } else { Usage(); System.exit(1); } //Process the local REALM RNAME details String[] rproperties = new String[4]; rproperties = parseRealmProperties(RNAME); //delete the data group specified mySelf.doit(rproperties, dataGroupName, deleteType); } /** * Prints the usage message for this class */ private static void Usage() { System.out.println("Usage ...\n"); System.out.println("deleteDataGroups \n"); System.out.println(" \n"); System.out.println(" - Data group name parameter to delete"); System.out.println(" - Data group delete by string(1) or object(2)"); System.out.println("\n\nNote: -? provides help on environment variables \n"); } } // End of deleteDataGroup Class