Search in sources :

Example 1 with VirtualAttributesModuleImplApi

use of cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi in project perun by CESNET.

the class Auditer method flush.

/**
	 * Imidiately flushes stored message for last top-level transaction into the log
	 *
	 */
public void flush() {
    List<List<List<AuditerMessage>>> topLevelTransactions = getTopLevelTransactions();
    if (topLevelTransactions.isEmpty()) {
        log.trace("No messages to flush");
        return;
    }
    List<List<AuditerMessage>> transactionChain = topLevelTransactions.get(topLevelTransactions.size() - 1);
    if (transactionChain.isEmpty()) {
        log.trace("No messages to flush");
        topLevelTransactions.remove(topLevelTransactions.size() - 1);
        return;
    }
    if (transactionChain.size() != 1) {
        log.error("There should be only one list of messages while flushing representing the most outer transaction.");
    }
    List<AuditerMessage> messages = transactionChain.get(0);
    topLevelTransactions.remove(topLevelTransactions.size() - 1);
    if (topLevelTransactions.isEmpty()) {
        TransactionSynchronizationManager.unbindResourceIfPossible(this);
    }
    log.trace("Audit messages was flushed for current transaction.");
    synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
        storeMessagesToDb(messages);
    }
    for (AuditerMessage message : messages) {
        for (VirtualAttributesModuleImplApi virtAttrModuleImplApi : registeredAttributesModules) {
            List<String> resolvingMessages = new ArrayList<String>();
            try {
                resolvingMessages.addAll(virtAttrModuleImplApi.resolveVirtualAttributeValueChange((PerunSessionImpl) message.getOriginaterPerunSession(), message.getMessage()));
            } catch (InternalErrorException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (WrongAttributeAssignmentException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (WrongReferenceAttributeValueException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (AttributeNotExistsException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            }
            if (!resolvingMessages.isEmpty()) {
                List<AuditerMessage> resolvingAuditerMessages = new ArrayList<>();
                for (String msg : resolvingMessages) {
                    resolvingAuditerMessages.add(new AuditerMessage(message.getOriginaterPerunSession(), msg));
                }
                storeMessagesToDb(resolvingAuditerMessages);
            }
        }
    }
}
Also used : VirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with VirtualAttributesModuleImplApi

use of cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi 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.");
}
Also used : UserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserVirtualAttributesModuleImplApi) ResourceGroupVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceGroupVirtualAttributesModuleImplApi) ResourceVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceVirtualAttributesModuleImplApi) MemberVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.MemberVirtualAttributesModuleImplApi) ResourceMemberVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceMemberVirtualAttributesModuleImplApi) UserExtSourceVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserExtSourceVirtualAttributesModuleImplApi) MemberGroupVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.MemberGroupVirtualAttributesModuleImplApi) FacilityUserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.FacilityUserVirtualAttributesModuleImplApi) FacilityVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.FacilityVirtualAttributesModuleImplApi) VirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserVirtualAttributesModuleImplApi) GroupAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.GroupAttributesModuleImplApi) ResourceGroupVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceGroupVirtualAttributesModuleImplApi) MemberGroupAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.MemberGroupAttributesModuleImplApi) ResourceVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceVirtualAttributesModuleImplApi) VoAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VoAttributesModuleImplApi) EntitylessAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.EntitylessAttributesModuleImplApi) MemberVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.MemberVirtualAttributesModuleImplApi) ResourceMemberVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceMemberVirtualAttributesModuleImplApi) UserAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserAttributesModuleImplApi) AttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.AttributesModuleImplApi) UserExtSourceVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserExtSourceVirtualAttributesModuleImplApi) ResourceAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceAttributesModuleImplApi) FacilityAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.FacilityAttributesModuleImplApi) FacilityUserAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.FacilityUserAttributesModuleImplApi) ResourceMemberAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceMemberAttributesModuleImplApi) UserExtSourceAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserExtSourceAttributesModuleImplApi) MemberGroupVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.MemberGroupVirtualAttributesModuleImplApi) MemberAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.MemberAttributesModuleImplApi) ResourceGroupAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.ResourceGroupAttributesModuleImplApi) FacilityUserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.FacilityUserVirtualAttributesModuleImplApi) FacilityVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.FacilityVirtualAttributesModuleImplApi) VirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi)

Aggregations

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 VirtualAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 AttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.AttributesModuleImplApi)1 EntitylessAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.EntitylessAttributesModuleImplApi)1 FacilityAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.FacilityAttributesModuleImplApi)1 FacilityUserAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.FacilityUserAttributesModuleImplApi)1 FacilityUserVirtualAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.FacilityUserVirtualAttributesModuleImplApi)1 FacilityVirtualAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.FacilityVirtualAttributesModuleImplApi)1 GroupAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.GroupAttributesModuleImplApi)1 MemberAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.MemberAttributesModuleImplApi)1 MemberGroupAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.MemberGroupAttributesModuleImplApi)1 MemberGroupVirtualAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.MemberGroupVirtualAttributesModuleImplApi)1 MemberVirtualAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.MemberVirtualAttributesModuleImplApi)1 ResourceAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.ResourceAttributesModuleImplApi)1 ResourceGroupAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.ResourceGroupAttributesModuleImplApi)1 ResourceGroupVirtualAttributesModuleImplApi (cz.metacentrum.perun.core.implApi.modules.attributes.ResourceGroupVirtualAttributesModuleImplApi)1