Skip to content

Instantly share code, notes, and snippets.

@sterym
Created August 8, 2013 06:42
Show Gist options
  • Save sterym/6182080 to your computer and use it in GitHub Desktop.
Save sterym/6182080 to your computer and use it in GitHub Desktop.
Roambi
/**
* Copy for user.
*
* @param camid the camid of the {@link CognosUser}
* @param cognosUser the {@link CognosUser}
* @param sourceCamId the source cam id
* @param cognos the {@link CognosService}
* @param config the {@link ProcessConfig}
*/
private void copyForUser(final String camid, final CognosUser cognosUser, final String sourceCamId,
final CognosService cognos, final ProcessConfig config) {
Map<String, String> params = new TreeMap<String, String>();
params.put("camid", camid);
params.put("userid", cognosUser.getSalesRepLogin());
params.put("fullname", cognosUser.getSalesRepName());
params.put("usernbr", cognosUser.getSalesRepNumber());
// Replaces placeholders with defined params
String src = Interpolator.interpolate(sourceCamId + config.getSourceFileFilter(), params);
String destination = camid + config.getDestinationLocation();
try {
cognos.copyUserFile(src, destination);
LOG.info("Copied data for user " + cognosUser.getSalesRepLogin());
} catch (CognosException e) {
//Handle error
}
}
/**
* Gets the cam id.
*
* @param userIds the user ids
* @return the {@link CamIdResponse}
* @throws CognosException the cognos exception
*/
@Override
public CamIdResponse getCamId(final Collection<String> userIds) throws CognosException {
Set<String> uids = new TreeSet<String>();
for (String u : userIds) {
uids.add(StringUtils.upperCase(u));
}
try {
SearchPathMultipleObject spMulti = new SearchPathMultipleObject();
spMulti.setValue("//account");
PropEnum[] props =
new PropEnum[] {PropEnum.searchPath, PropEnum.objectClass, PropEnum.defaultName, PropEnum.userName};
BaseClass[] bc = cmService.query(spMulti, props, new Sort[] {}, new QueryOptions());
Map<String, String> res = new TreeMap<String, String>();
if (bc != null && bc.length > 0) {
// Display all objects in My Folders for user userName
for (int i = 0; i < bc.length && !uids.isEmpty(); i++) {
Account user = (Account) bc[i];
String uid = StringUtils.upperCase(user.getUserName().getValue());
if (uid != null && uids.remove(uid)) {
res.put(uid, user.getSearchPath().getValue());
}
}
} else {
throw new CognosException("Could not find any of the users: " + uids);
}
return new CamIdResponse(res);
} catch (RuntimeException e) {
throw new CognosException("Could not resolve user ids in cognos: " + e.getMessage(), e);
} catch (RemoteException e) {
throw new CognosException("Could not resolve user ids in cognos: " + e.getMessage(), e);
}
}
/**
* Copy user file.
*
* @param fromSearchPath the from search path
* @param toSearchPath the to search path
* @throws CognosException the cognos exception
*/
@Override
public void copyUserFile(final String fromSearchPath, final String toSearchPath) throws CognosException {
try {
SearchPathMultipleObject spMulti = new SearchPathMultipleObject();
spMulti.setValue(fromSearchPath);
// Will copy all reports in My Folders to the specified user's My
// Folders
PropEnum[] props =
new PropEnum[] {PropEnum.searchPath, PropEnum.objectClass, PropEnum.defaultName, PropEnum.portalPage};
// Query the Content Store for all reports in My Folders for user
// userName
BaseClass[] bc = cmService.query(spMulti, props, new Sort[] {}, new QueryOptions());
if (bc != null && bc.length > 0) {
// Display all objects in My Folders for user userName
if (LOG.isTraceEnabled()) {
LOG.trace("Objects in My Folders for user " + fromSearchPath);
}
if (LOG.isTraceEnabled()) {
for (int i = 0; i < bc.length; i++) {
UiClass toAdd = (UiClass) bc[i];
LOG.trace(toAdd.getObjectClass().getValue().getValue() + " - "
+ toAdd.getDefaultName().getValue());
}
}
SearchPathSingleObject spSingle = new SearchPathSingleObject();
spSingle.setValue(toSearchPath);
CopyOptions co = new CopyOptions();
// NOTE: This will replace existing reports.
co.setUpdateAction(UpdateActionEnum.replace);
cmService.copy(bc, spSingle, co);
} else {
throw new CognosException("No objects found in the My Folders for user " + fromSearchPath
+ " in cognos.");
}
} catch (RuntimeException e) {
throw new CognosException("Could not copy data in cognos: " + e.getMessage(), e);
} catch (RemoteException e) {
throw new CognosException("Could not copy data in cognos: " + e.getMessage(), e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment