Selamlar,
Küçük bir proje üzerinde çalışıyorum. Oluşturduğum methodlarda, sürekli try catch ten dolayı hata alıyorum. Tüm istediği try catchleri eklediğim zamanda çok karmaşık bir kod haline geldi. Kodu daha sade bir hale getirmede yardımcı olabilir misiniz? Bu konuda neler yapabilirim? Aşağıda classı paylaşıyorum.
Teşekkürler.
import java.util.ArrayList;
import java.util.List;
import sailpoint.api.SailPointContext;
import sailpoint.api.SailPointFactory;
import sailpoint.spring.SpringStarter;
import sailpoint.tools.GeneralException;
import sailpoint.object.*;
import sailpoint.object.IdentitySelector.MatchExpression;
import sailpoint.object.IdentitySelector.MatchTerm;
public class RolesImport {
public static SailPointContext context;
public static String itRolesImport(String roleName, String ORGroleName, String applicationType,
String attributeType, String attributeValue) {
Application application = null;
try {
application = context.getObject(Application.class, applicationType);
} catch (GeneralException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
Bundle ITrole = null;
try {
ITrole = context.getObject(Bundle.class, roleName);
} catch (GeneralException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Filter f = Filter.eq("Groups", "Akbank");
List profiles = new ArrayList();
Profile p = new Profile();
p.setApplication(application);
p.addConstraint(f);
profiles.add(p);
if (null == ITrole) {
System.out.println("in if");
Bundle newITRole = new sailpoint.object.Bundle();
newITRole.setName(roleName);
newITRole.setType("it");
newITRole.setProfiles(profiles);
try {
context.saveObject(newITRole);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
System.out.println("role is exist and role type is : " + ITrole.getType());
}
return "IT Roles..";
}
public static String businessRolesImport(String roleName, String ORGroleName, String ITroleName, List matchName,
List matchValue) {
Bundle requiredITrole = null;
try {
requiredITrole = context.getObject(Bundle.class, ITroleName);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bundle inheritenceOrgRole = null;
try {
inheritenceOrgRole = context.getObject(Bundle.class, ORGroleName);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List requiredBundles = new ArrayList();
requiredBundles.add(requiredITrole);
IdentitySelector sel = new IdentitySelector();
MatchExpression mat = new MatchExpression();
MatchTerm matchtTerm = new MatchTerm();
for (int i = 0; i <= matchName.size(); i++) {
matchtTerm.setName((String) matchName.get(i));
matchtTerm.setValue((String) matchValue.get(i));
mat.addTerm(matchtTerm);
}
mat.setAnd(true);
sel.setMatchExpression(mat);
Bundle role = null;
try {
role = context.getObject(Bundle.class, roleName);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (null == role) {
Bundle newRole = new sailpoint.object.Bundle();
newRole.setName(roleName);
newRole.setType("business");
newRole.setSelector(sel);
try {
context.saveObject(newRole);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
role.setRequirements(requiredBundles);
try {
context.saveObject(role);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
{
System.out.println("role is exist and role type is : " + role.getType());
role.setRequirements(requiredBundles);
try {
context.saveObject(role);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "Business Roles..";
}
public static String organizationalRolesImport(String roleName, String ORGroleName) {
Bundle role = null;
try {
role = context.getObject(Bundle.class, roleName);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (null == role) {
Bundle newRole = new sailpoint.object.Bundle();
newRole.setName(roleName);
newRole.setType("organizational");
try {
context.saveObject(newRole);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
context.saveObject(role);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
{
System.out.println("role is exist and role type is : " + role.getType());
try {
context.saveObject(role);
} catch (GeneralException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "Organizational Role..";
}
public static void main(String[] args) throws Exception {
SpringStarter starter = new SpringStarter("iiqBeans");// SpringStarter("iiqBeans"); //IIQ propeties file must be
// present in java project.
starter.start();
SailPointContext context = SailPointFactory.createContext();
//Identity identity = context.getObject(Identity.class, "99910010001");
////////////////////////////////////////////////////////////////////////////////
String roleName = "TEST IT Role";
String roleType = "IT";
String applicationType = "G Suite";
String attributeType = "Groups";
String attributeValue = "Akbank";
String ITroleName = "TEST IT Role";
String ORGroleName = "TEST ORG Role";
List matchName = new ArrayList();
matchName.add("inactive");
matchName.add("depcode");
matchName.add("jobcode");
List matchValue = new ArrayList();
matchValue.add("false");
matchValue.add("123");
matchValue.add("321");
if (roleType.equals("IT")) {
itRolesImport(roleName, ORGroleName, applicationType, attributeType, attributeValue);
}
if (roleType.equals("Business")) {
businessRolesImport(roleName, ORGroleName, ITroleName, matchName, matchValue);
}
if (roleType.equals("Organization")) {
organizationalRolesImport(ORGroleName, roleName);
}
context.commitTransaction();
///////////////////////////////////////////////////////////////////////////////////////
starter.close();
}
}