Skip to content

Instantly share code, notes, and snippets.

@iggymacd
Created April 24, 2012 13:17
Show Gist options
  • Save iggymacd/2479609 to your computer and use it in GitHub Desktop.
Save iggymacd/2479609 to your computer and use it in GitHub Desktop.
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.exception.ExceptionUtils;
import com.mitratech.teamconnect.base.BQGroupAccess;
import com.mitratech.teamconnect.base.YQGroup;
import com.mitratech.teamconnect.base.factory.GQGrupStore;
import com.mitratech.teamconnect.entity.BNEnterpriseObject;
import com.mitratech.teamconnect.entity.BNGroupAccess;
import com.mitratech.teamconnect.entity.TNProject;
import com.mitratech.teamconnect.entity.WNObjdCategory;
import com.mitratech.teamconnect.entity.YNGroup;
import com.mitratech.teamconnect.entity.factory.FNUtility;
import com.mitratech.teamconnect.entity.factory.GNGrupStore;
import com.mitratech.teamconnect.foundation.Callable;
import com.mitratech.teamconnect.foundation.TCDefaultActionHandler;
import com.mitratech.teamconnect.foundation.TCException;
import com.mitratech.teamconnect.foundation.TCLog;
import com.mitratech.teamconnect.foundation.TCUtility;
import com.mitratech.teamconnect.foundation.ZNAllowDenyIID;
import com.mitratech.teamconnect.foundation.ZNSecurityTypeIID;
public class CORA_SetComplianceSecurity_CU extends TCDefaultActionHandler {
TNProject project = null;
@Override
public void action() {
String RULE_NAME = getClassName();
log("Start Of Rule :" + RULE_NAME);
try {
FNUtility.runAsSystemUser(new Callable() {
public void call() {
doAction();
}
});
} catch (TCException e) {
log("Exception : " + getClassName());
log("Exception : " + ExceptionUtils.getStackTrace(e));
} catch (Exception e) {
log("Exception : " + getClassName());
log("Exception Details : " + ExceptionUtils.getStackTrace(e));
} finally {
log("End Of Rule : " + RULE_NAME);
}
}
public void doAction() {
project = (TNProject) getObject();
try {
if (project != null) {
List<WNObjdCategory> categoryList = project.getCategoryList();
if (categoryList != null && categoryList.size() > 0) {
for (WNObjdCategory category : categoryList) {
if (category != null) {
log("Category ---> " + category.getDisplayString());
if (category.getPartialTreePosition()
.equalsIgnoreCase("COMP")) {
log("Category is ---> "
+ category.getDisplayString()
+ " code: "
+ category.getPartialTreePosition());
project.setSecurityTypeIID(ZNSecurityTypeIID.PRIVATE);
addGroupAccess(project, "Compliance Reviewer",
ZNAllowDenyIID.ALLOW, true, false,
false, true);
addGroupAccess(project, "Compliance Admin",
ZNAllowDenyIID.ALLOW, true, false,
true, true);
}
}
}
}
}
} catch (Exception e) {
log("Exception : " + ExceptionUtils.getStackTrace(e));
}
}
public void parameterDeclaration() {
}
public void log(String msg) {
TCLog.getRuleLogger().debug(msg);
TCLog.getRuleLogger().warn(msg);
TCLog.getXmlLogger().info(msg);
}
public static void addGroupAccess(BNEnterpriseObject bneObject,
String groupName, char allowDeny, boolean readAccess,
boolean deleteAccess, boolean setPermission, boolean updateAccess) {
YNGroup targetGroup = GNGrupStore.getGroupForName(groupName);
BNGroupAccess existingAccess = getGroupAccessByName(bneObject,
groupName);
if (existingAccess != null) {
((BQGroupAccess) existingAccess).setAllowDenyIIDQ(allowDeny);
((BQGroupAccess) existingAccess).setIsReadQ(readAccess);
((BQGroupAccess) existingAccess).setIsUpdateQ(updateAccess);
((BQGroupAccess) existingAccess).setIsDeleteQ(deleteAccess);
((BQGroupAccess) existingAccess).setIsPermQ(setPermission);
} else if (targetGroup != null) {
bneObject.addGroupAccess(targetGroup.getPrimaryKey() + "",
allowDeny, readAccess, deleteAccess, setPermission,
updateAccess);
}
}
private static BNGroupAccess getGroupAccessByName(
BNEnterpriseObject bneObject, String targetGroupName) {
boolean isTargetGroupAccessExit = false;
int groupAccessCount = 0;
List groupAccessList = bneObject.getGroupAccessList();
for (Iterator iter = groupAccessList.iterator(); iter.hasNext();) {
groupAccessCount++;
BNGroupAccess aGroupAccess = (BNGroupAccess) iter.next();
String aGroupName = aGroupAccess.getGroup().getName();
isTargetGroupAccessExit = aGroupName.equals(targetGroupName);
if (isTargetGroupAccessExit) {
return aGroupAccess;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment