123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- import com.cognos.developer.schemas.bibus._3.Account;
- import com.cognos.developer.schemas.bibus._3.AddOptions;
- import com.cognos.developer.schemas.bibus._3.AuthoredReport;
- import com.cognos.developer.schemas.bibus._3.BaseClass;
- import com.cognos.developer.schemas.bibus._3.ConfigurationData;
- import com.cognos.developer.schemas.bibus._3.ConfigurationDataEnum;
- import com.cognos.developer.schemas.bibus._3.CopyOptions;
- import com.cognos.developer.schemas.bibus._3.DeleteOptions;
- import com.cognos.developer.schemas.bibus._3.Folder;
- import com.cognos.developer.schemas.bibus._3.Locale;
- import com.cognos.developer.schemas.bibus._3.MoveOptions;
- import com.cognos.developer.schemas.bibus._3.PropEnum;
- import com.cognos.developer.schemas.bibus._3.QueryOptions;
- import com.cognos.developer.schemas.bibus._3.Report;
- import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
- import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
- import com.cognos.developer.schemas.bibus._3.Sort;
- import com.cognos.developer.schemas.bibus._3.StringProp;
- import com.cognos.developer.schemas.bibus._3.TokenProp;
- import com.cognos.developer.schemas.bibus._3.UpdateActionEnum;
- import com.cognos.developer.schemas.bibus._3.UpdateOptions;
- public class CSHandlers
- {
-
- public BaseClass addObjectToCS(
- CRNConnect connection,
- BaseClass bc,
- String path)
- throws java.rmi.RemoteException
- {
-
- AddOptions ao = new AddOptions();
- ao.setUpdateAction(UpdateActionEnum.replace);
- return connection.getCMService().add(new SearchPathSingleObject(path), new BaseClass[] { bc }, ao)[0];
-
- }
-
- public AuthoredReport addReportToCS(
- CRNConnect connection,
- Report rprt,
- String path)
- throws java.rmi.RemoteException
- {
-
- AddOptions ao = new AddOptions();
- ao.setUpdateAction(UpdateActionEnum.replace);
- return connection.getReportService().add(new SearchPathSingleObject(path), rprt, ao);
-
- }
- public BaseClass[] createDirectoryInCS(
- CRNConnect connection,
- String parentPath,
- String directoryName)
- throws java.rmi.RemoteException
- {
- TokenProp directoryNameTokenProp = new TokenProp();
- directoryNameTokenProp.setValue(directoryName);
- Folder directory = new Folder();
- directory.setDefaultName(directoryNameTokenProp);
- BaseClass[] directoryList = new BaseClass[] { directory };
- AddOptions addOpts = new AddOptions();
- addOpts.setUpdateAction(UpdateActionEnum.update);
- return connection.getCMService().add(new SearchPathSingleObject(parentPath), directoryList, addOpts);
- }
-
- public boolean deleteObjectFromCS(
- CRNConnect connection,
- BaseClass bc)
- throws java.rmi.RemoteException
- {
-
- DeleteOptions del = new DeleteOptions();
- del.setForce(true);
- int i = connection.getCMService().delete(new BaseClass[] { bc }, del);
-
- return (i > 0);
- }
-
- public BaseClass[] updateObjectInCS(
- CRNConnect connection,
- BaseClass[] bc)
- throws java.rmi.RemoteException
- {
-
- return connection.getCMService().update(bc, new UpdateOptions());
-
- }
-
- public BaseClass[] moveObjectsInCS(
- CRNConnect connection,
- BaseClass[] bc,
- String targetPath)
- {
- try
- {
-
- return connection.getCMService().move(bc, new SearchPathSingleObject(targetPath), new MoveOptions());
-
- }
- catch (java.rmi.RemoteException remoteEx)
- {
- remoteEx.printStackTrace();
- return null;
- }
- }
-
- public void moveReports(
- CRNConnect connection,
- String[] reportPath,
- String targetPath)
- {
-
- BaseClass[] obj = new BaseClass[1];
- obj[0] = new Report();
- StringProp path = new StringProp();
- path.setValue(reportPath[0]);
- obj[0].setSearchPath(path);
- obj = moveObjectsInCS(connection, obj, targetPath);
- System.out.println("");
- System.out.println("Here is the list of items that were moved.");
- if (obj != null)
- {
- for (int i = 0; i < obj.length; i++)
- {
- System.out.println(
- "Name:" + obj[i].getDefaultName().getValue());
- }
- }
- else
- {
- System.out.println("No items were moved.");
- }
- }
-
- public BaseClass[] copyObjectsInCS(
- CRNConnect connection,
- BaseClass[] bc,
- String targetPath)
- {
- try
- {
-
- return connection.getCMService().copy(bc, new SearchPathSingleObject(targetPath), new CopyOptions());
-
- }
- catch (java.rmi.RemoteException remoteEx)
- {
- remoteEx.printStackTrace();
- return null;
- }
- }
-
- public boolean copyReports(
- CRNConnect connection,
- String[] reportPath,
- String targetPath)
- {
- BaseClass[] obj = new BaseClass[1];
- StringProp path = new StringProp();
- path.setValue(reportPath[0]);
- obj[0] = new Report();
- obj[0].setSearchPath(path);
- obj = copyObjectsInCS(connection, obj, targetPath);
- if (obj != null)
- {
- System.out.println("Here is the list of items that were copied.");
- for (int i = 0; i < obj.length; i++)
- {
- System.out.println(
- "Name:" + obj[i].getDefaultName().getValue());
- }
- return true;
- }
- else
- {
- System.out.println("No items were copied.");
- return false;
- }
- }
-
- public void takeOwnerShip(CRNConnect connection, BaseClass bc)
- {
- Account me = Logon.getLogonAccount(connection);
- bc.setOwner(me.getOwner());
- }
-
- public void takeOwnerShipOfReport(
- CRNConnect connection,
- String[] reportPath)
- {
- BaseClass[] bc = new BaseClass[1];
- StringProp path = new StringProp();
- path.setValue(reportPath[0]);
- bc[0] = new Report();
- bc[0].setSearchPath(path);
- takeOwnerShip(connection, bc[0]);
- }
-
- public BaseClass[] queryObjectInCS(
- CRNConnect connection,
- String path)
- throws java.rmi.RemoteException
- {
-
- PropEnum properties[] =
- new PropEnum[] { PropEnum.defaultName, PropEnum.searchPath };
-
- return queryObjectInCS(connection, path, properties);
- }
-
- public BaseClass[] queryObjectInCS(
- CRNConnect connection,
- String path,
- PropEnum[] properties)
- throws java.rmi.RemoteException
- {
-
-
-
- Sort sort[] = new Sort[] { new Sort()};
- return queryObjectInCS(connection, path, properties, sort);
- }
-
- public BaseClass[] queryObjectInCS(
- CRNConnect connection,
- String path,
- PropEnum[] properties,
- Sort sort[])
- throws java.rmi.RemoteException
- {
-
-
-
- QueryOptions qop = new QueryOptions();
-
- return connection.getCMService().query(new SearchPathMultipleObject(path), properties, sort, qop);
- }
-
- public String getParentPath(
- CRNConnect connection,
- String searchPath)
- {
- String parentPath = "";
- Sort sortArray[] = { new Sort()};
- QueryOptions queryOptions = new QueryOptions();
- PropEnum props[] =
- new PropEnum[] {
- PropEnum.searchPath,
- PropEnum.defaultName,
- PropEnum.parent };
- try
- {
- BaseClass child[];
- child = connection.getCMService().query(new SearchPathMultipleObject(searchPath), props, sortArray, queryOptions);
- if (child != null && (child.length > 0))
- {
- String[] parents = new String[child.length];
- for (int i = 0; i < child.length; i++)
- {
- parents[i] =
- child[i]
- .getParent()
- .getValue()[0]
- .getSearchPath()
- .getValue();
- }
- parentPath = parents[0];
- }
- }
- catch (java.rmi.RemoteException remoteEx)
- {
- return "";
- }
- return parentPath;
- }
-
- public String[] getReportPath(
- CRNConnect connection,
- String reportName)
- {
- Sort sortArray[] = { new Sort()};
- QueryOptions queryOptions = new QueryOptions();
- PropEnum props[] =
- new PropEnum[] { PropEnum.searchPath, PropEnum.defaultName };
- try
- {
- BaseClass repPth[];
- String quotChar = "\'";
- if (reportName.indexOf(quotChar) >= 0)
- {
- quotChar = "\"";
- }
- repPth =
- connection.getCMService().query(
- new SearchPathMultipleObject
- ("/content//report[@name="
- + quotChar
- + reportName
- + quotChar
- + "]"),
- props,
- sortArray,
- queryOptions);
- if (repPth != null && (repPth.length > 0))
- {
- String[] reportPath = new String[repPth.length];
- for (int i = 0; i < repPth.length; i++)
- {
- reportPath[i] = repPth[i].getSearchPath().getValue();
- }
- return reportPath;
- }
- else
- {
- quotChar = "\'";
- if (reportName.indexOf(quotChar) >= 0)
- {
- quotChar = "\"";
- }
- repPth =
- connection.getCMService().query(
- new SearchPathMultipleObject
- ("/content//query[@name="
- + quotChar
- + reportName
- + quotChar
- + "]"),
- props,
- sortArray,
- queryOptions);
- if (repPth != null && (repPth.length > 0))
- {
-
-
- String[] reportPath = new String[repPth.length];
- for (int i = 0; i < repPth.length; i++)
- {
- reportPath[i] = repPth[i].getSearchPath().getValue();
- }
- return reportPath;
- }
- }
- return null;
- }
- catch (java.rmi.RemoteException remoteEx)
- {
- System.out.println(remoteEx.getMessage());
- return null;
- }
- }
-
- public Locale[] getConfiguration(CRNConnect connection)
- {
- ConfigurationData data = null;
- Locale[] locales = null;
- ConfigurationDataEnum[] config = new ConfigurationDataEnum[1];
- config[0] = ConfigurationDataEnum.fromString("serverLocale");
- try
- {
-
- data = connection.getSystemService().getConfiguration(config);
- locales = data.getServerLocale();
-
- if (locales == null)
- {
- System.out.println("No serverLocale configured!");
- }
- }
- catch (java.rmi.RemoteException remoteEx)
- {
- remoteEx.printStackTrace();
- }
- return locales;
- }
- }
|