use of cz.metacentrum.perun.core.implApi.modules.attributes.AttributesModuleImplApi in project perun by CESNET.
the class AttributesManagerBlImpl method initialize.
protected void initialize() throws InternalErrorException {
log.debug("AttributesManagerBlImpl initialize started.");
//Get PerunSession
String attributesManagerInitializator = "attributesManagerBlImplInitializator";
PerunPrincipal pp = new PerunPrincipal(attributesManagerInitializator, ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
PerunSession sess = perunBl.getPerunSession(pp, new PerunClient());
//Prepare all attribute definition from system perun
Set<AttributeDefinition> allAttributesDef = new HashSet<AttributeDefinition>();
allAttributesDef.addAll(this.getAttributesDefinition(sess));
//Basic state of all maps (record for every existing attributeDefinitions)
for (AttributeDefinition ad : allAttributesDef) {
dependencies.put(ad, new HashSet<AttributeDefinition>());
strongDependencies.put(ad, new HashSet<AttributeDefinition>());
inverseDependencies.put(ad, new HashSet<AttributeDefinition>());
inverseStrongDependencies.put(ad, new HashSet<AttributeDefinition>());
allDependencies.put(ad, new HashSet<AttributeDefinition>());
}
log.debug("Dependencies and StrongDependencies filling started.");
//Fill dep and strongDep maps
for (AttributeDefinition ad : allAttributesDef) {
AttributesModuleImplApi module = null;
List<String> depList = new ArrayList<String>();
List<String> strongDepList = new ArrayList<String>();
Set<AttributeDefinition> depSet = new HashSet<AttributeDefinition>();
Set<AttributeDefinition> strongDepSet = new HashSet<AttributeDefinition>();
//Return null to object if module not exist
Object attributeModule = getAttributesManagerImpl().getAttributesModule(sess, ad);
//If there is any existing module
if (attributeModule != null) {
module = (AttributesModuleImplApi) attributeModule;
depList = module.getDependencies();
strongDepList = module.getStrongDependencies();
//Fill Set of dependencies
for (String s : depList) {
if (!s.endsWith("*")) {
try {
AttributeDefinition attrDef = getAttributeDefinition(sess, s);
depSet.add(attrDef);
} catch (AttributeNotExistsException ex) {
log.error("For attribute name " + s + "can't be found attributeDefinition at Inicialization in AttributesManagerBlImpl.");
}
//If there is something like AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace" + ":*" we need to replace * by all possibilities
} else {
List<String> allVariantOfDependence = getAllSimilarAttributeNames(sess, s.substring(0, s.length() - 2));
for (String variant : allVariantOfDependence) {
try {
AttributeDefinition attrDef = getAttributeDefinition(sess, variant);
depSet.add(attrDef);
} catch (AttributeNotExistsException ex) {
log.error("For attribute name " + variant + "can't be found attributeDefinition at Inicialization in AttributesManagerBlImpl.");
}
}
}
}
//Fil Set of strongDependencies
for (String s : strongDepList) {
if (!s.endsWith("*")) {
try {
AttributeDefinition attrDef = getAttributeDefinition(sess, s);
strongDepSet.add(attrDef);
} catch (AttributeNotExistsException ex) {
log.error("For attribute name " + s + "can't be found attributeDefinition at Inicialization in AttributesManagerBlImpl.");
}
//If there is something like AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace" + ":*" we need to replace * by all possibilities
} else {
List<String> allVariantOfDependence = getAllSimilarAttributeNames(sess, s.substring(0, s.length() - 2));
for (String variant : allVariantOfDependence) {
try {
AttributeDefinition attrDef = getAttributeDefinition(sess, variant);
strongDepSet.add(attrDef);
} catch (AttributeNotExistsException ex) {
log.error("For attribute name " + variant + "can't be found attributeDefinition at Inicialization in AttributesManagerBlImpl.");
}
}
}
}
}
dependencies.put(ad, depSet);
strongDependencies.put(ad, strongDepSet);
}
log.debug("Dependencies and StrongDependencies was filled successfully.");
log.debug("InverseDependencies and InverseStrongDependencies filling started.");
//First create inversion map for simple dependencies
Set<AttributeDefinition> depSet = dependencies.keySet();
for (AttributeDefinition key : depSet) {
Set<AttributeDefinition> keySet = new HashSet<AttributeDefinition>();
keySet = dependencies.get(key);
for (AttributeDefinition keySetItem : keySet) {
Set<AttributeDefinition> changeSet = new HashSet<AttributeDefinition>();
changeSet = inverseDependencies.get(keySetItem);
changeSet.add(key);
//inverseDependencies.put(keySetItem, changeSet);
}
}
//Second create inversion map for strong dependencies
depSet = strongDependencies.keySet();
for (AttributeDefinition key : depSet) {
Set<AttributeDefinition> keySet = new HashSet<AttributeDefinition>();
keySet = strongDependencies.get(key);
for (AttributeDefinition keySetItem : keySet) {
Set<AttributeDefinition> changeSet = new HashSet<AttributeDefinition>();
changeSet = inverseStrongDependencies.get(keySetItem);
changeSet.add(key);
//inverseDependencies.put(keySetItem, changeSet);
}
}
log.debug("InverseDependencies and InverseStrongDependencies was filled successfully.");
log.debug("Cycle test of InverseStrongDependencies started.");
if (isMapOfAttributesDefCyclic(inverseStrongDependencies)) {
log.error("There is cycle in inverseStrongDependencies so map of All attribute will be not created!");
} else {
log.debug("Cycle test of InverseStrongDependencies was successfull.");
log.debug("Filling map of allDependencies started.");
for (AttributeDefinition key : allDependencies.keySet()) {
List<AttributeDefinition> stackingAttributes = new ArrayList<AttributeDefinition>();
Set<AttributeDefinition> dependenciesOfAttribute = new HashSet<AttributeDefinition>();
dependenciesOfAttribute.addAll(inverseStrongDependencies.get(key));
dependenciesOfAttribute.addAll(inverseDependencies.get(key));
stackingAttributes.addAll(inverseStrongDependencies.get(key));
while (!stackingAttributes.isEmpty()) {
AttributeDefinition firstAttr = stackingAttributes.get(0);
stackingAttributes.remove(firstAttr);
dependenciesOfAttribute.addAll(inverseStrongDependencies.get(firstAttr));
dependenciesOfAttribute.addAll(inverseDependencies.get(firstAttr));
stackingAttributes.addAll(inverseStrongDependencies.get(firstAttr));
}
allDependencies.put(key, dependenciesOfAttribute);
}
log.debug("Map of allDependencies was filled successfully.");
}
//DEBUG creating file with all dependencies of all attributes (180+- on devel)
/*String pathToFile = "./AllDependencies.log";
File f = new File(pathToFile);
try {
f.createNewFile();
PrintWriter writer;
writer = new PrintWriter(new FileWriter(f, true));
int i=1;
for(AttributeDefinition ad: allDependencies.keySet()) {
writer.println(i + ") " + ad.toString());
for(AttributeDefinition a: allDependencies.get(ad)) {
writer.println(" ---> " + a);
}
i++;
}
writer.close();
} catch (IOException ex) {
log.error("Error at saving AllDependencies file.");
}*/
//DEBUG end
log.debug("AttributesManagerBlImpl initialize ended.");
}
use of cz.metacentrum.perun.core.implApi.modules.attributes.AttributesModuleImplApi in project perun by CESNET.
the class AttributesManagerImpl method initialize.
protected void initialize() throws InternalErrorException {
log.debug("AttributesManagerImpl initialize started.");
//Get PerunSession
//String attributesManagerInitializator = "attributesManagerInitializator";
//PerunPrincipal pp = new PerunPrincipal(attributesManagerInitializator, ExtSourcesManager.EXTSOURCE_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
//PerunSession sess = perun.getPerunSession(pp);
//load all attributes modules
ServiceLoader<AttributesModuleImplApi> attributeModulesLoader = ServiceLoader.load(AttributesModuleImplApi.class);
for (AttributesModuleImplApi module : attributeModulesLoader) {
attributesModulesMap.put(module.getClass().getName(), module);
if (module instanceof VirtualAttributesModuleImplApi) {
Auditer.registerAttributeModule((VirtualAttributesModuleImplApi) module);
}
log.debug("Module " + module.getClass().getSimpleName() + " loaded.");
}
Utils.notNull(jdbc, "jdbc");
//check if all core atributes exists, create it doesn't
List<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>();
//Facility.id
AttributeDefinition attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Facility id");
attributes.add(attr);
//Facility.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Facility name");
attributes.add(attr);
//Resource.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Resource id");
attributes.add(attr);
//Resource.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Resource name");
attributes.add(attr);
//Resource.description
attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("description");
attr.setDisplayName("Resource description");
attributes.add(attr);
//Member.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Member id");
attributes.add(attr);
//User.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("User id");
attributes.add(attr);
//User.firstName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("firstName");
attr.setDisplayName("User first name");
attributes.add(attr);
//User.lastName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("lastName");
attr.setDisplayName("User last name");
attributes.add(attr);
//User.middleName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("middleName");
attr.setDisplayName("User middle name");
attributes.add(attr);
//User.titleBefore
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("titleBefore");
attr.setDisplayName("User title before");
attributes.add(attr);
//User.titleAfter
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("titleAfter");
attr.setDisplayName("User title after");
attributes.add(attr);
//User.serviceUser
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(Boolean.class.getName());
attr.setFriendlyName("serviceUser");
attr.setDisplayName("If user is service user or not.");
attributes.add(attr);
//Group.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Group id");
attributes.add(attr);
//Group.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Group full name");
attributes.add(attr);
//Group.description
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("description");
attr.setDisplayName("Group description");
attributes.add(attr);
//Group.parentGroupId
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("parentGroupId");
attr.setDisplayName("Id of group's parent group.");
attributes.add(attr);
//Vo.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Vo id");
attributes.add(attr);
//Vo.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Vo full name");
attributes.add(attr);
//Vo.createdAt
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("createdAt");
attr.setDisplayName("Vo created date");
attributes.add(attr);
//Vo.shortName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("shortName");
attr.setDisplayName("Vo short name");
attributes.add(attr);
//Host.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_HOST_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Host id");
attributes.add(attr);
//Host.hostname
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_HOST_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("hostname");
attr.setDisplayName("Host hostname");
attributes.add(attr);
// *** Def attributes
//urn:perun:group:attribute-def:def:groupExtSource
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("groupExtSource");
attr.setDisplayName("Group extSource");
attributes.add(attr);
//urn:perun:group:attribute-def:def:groupMembersExtSource
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("groupMembersExtSource");
attr.setDisplayName("Group members extSource");
attributes.add(attr);
//urn:perun:group:attribute-def:def:groupMembersQuery
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("groupMembersQuery");
attr.setDisplayName("Group members query");
attributes.add(attr);
//urn:perun:group:attribute-def:def:synchronizatinEnabled
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("synchronizationEnabled");
attr.setDisplayName("Group synchronization enabled");
attr.setDescription("Enables group synchronization from external source.");
attributes.add(attr);
//urn:perun:group:attribute-def:def:synchronizationInterval
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("synchronizationInterval");
attr.setDisplayName("Synchronization interval");
attr.setDescription("Time between two successful synchronizations.");
attributes.add(attr);
//urn:perun:group:attribute-def:def:lastSynchronizationState
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setDescription("If group is synchronized, there will be information about state of last synchronization.");
attr.setFriendlyName("lastSynchronizationState");
attr.setDisplayName("Last synchronization state");
attributes.add(attr);
//urn:perun:group:attribute-def:def:lastSynchronizationTimestamp
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setDescription("If group is synchronized, there will be the last timestamp of group synchronization.");
attr.setFriendlyName("lastSynchronizationTimestamp");
attr.setDisplayName("Last Synchronization timestamp");
attributes.add(attr);
if (perun.isPerunReadOnly())
log.debug("Loading attributes manager init in readOnly version.");
for (AttributeDefinition attribute : attributes) {
if (!checkAttributeExistsForInitialize(attribute)) {
if (perun.isPerunReadOnly()) {
throw new InternalErrorException("There is missing required attribute " + attribute + " and can't be created because this instance is read only.");
} else {
self.createAttributeExistsForInitialize(attribute);
}
}
}
log.debug("AttributesManagerImpl initialize ended.");
}
Aggregations