Search in sources :

Example 1 with Owner

use of cz.metacentrum.perun.core.api.Owner in project perun by CESNET.

the class FacilitiesManagerBlImpl method removeFacilityContact.

@Override
public void removeFacilityContact(PerunSession sess, ContactGroup contactGroupToRemove) throws InternalErrorException {
    if (contactGroupToRemove != null) {
        if (contactGroupToRemove.getUsers() != null) {
            List<Integer> usersId = new ArrayList<>();
            for (RichUser user : contactGroupToRemove.getUsers()) {
                usersId.add(user.getId());
                this.facilitiesManagerImpl.removeFacilityContact(sess, contactGroupToRemove.getFacility(), contactGroupToRemove.getName(), user);
            }
            sess.getPerun().getAuditer().log(sess, "Users (" + usersId.toString() + ") successfully removed from contact group " + contactGroupToRemove.toString() + ".");
        }
        if (contactGroupToRemove.getGroups() != null) {
            List<Integer> groupsId = new ArrayList<>();
            for (Group group : contactGroupToRemove.getGroups()) {
                groupsId.add(group.getId());
                this.facilitiesManagerImpl.removeFacilityContact(sess, contactGroupToRemove.getFacility(), contactGroupToRemove.getName(), group);
            }
            sess.getPerun().getAuditer().log(sess, "Groups (" + groupsId.toString() + ") successfully removed from contact group " + contactGroupToRemove.toString() + ".");
        }
        if (contactGroupToRemove.getOwners() != null) {
            List<Integer> ownersId = new ArrayList<>();
            for (Owner owner : contactGroupToRemove.getOwners()) {
                ownersId.add(owner.getId());
                this.facilitiesManagerImpl.removeFacilityContact(sess, contactGroupToRemove.getFacility(), contactGroupToRemove.getName(), owner);
            }
            sess.getPerun().getAuditer().log(sess, "Owners (" + ownersId.toString() + ") successfully removed from contact group " + contactGroupToRemove.toString() + ".");
        }
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Owner(cz.metacentrum.perun.core.api.Owner) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList)

Example 2 with Owner

use of cz.metacentrum.perun.core.api.Owner in project perun by CESNET.

the class FacilitiesManagerEntry method checkFacilityContactEntitiesExists.

/**
	 * Check existence of every entity in contactGroup
	 *
	 * @param sess
	 * @param contactGroup
	 * @throws FacilityNotExistsException
	 * @throws UserNotExistsException
	 * @throws OwnerNotExistsException
	 * @throws GroupNotExistsException
	 * @throws InternalErrorException
	 */
private void checkFacilityContactEntitiesExists(PerunSession sess, ContactGroup contactGroup) throws FacilityNotExistsException, UserNotExistsException, OwnerNotExistsException, GroupNotExistsException, InternalErrorException {
    Utils.notNull(contactGroup, "contactGroup");
    Utils.notNull(contactGroup.getFacility(), "facility");
    Utils.notNull(contactGroup.getName(), "name");
    this.getFacilitiesManagerBl().checkFacilityExists(sess, contactGroup.getFacility());
    if (contactGroup.getUsers() != null) {
        for (RichUser user : contactGroup.getUsers()) {
            getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
        }
    }
    if (contactGroup.getGroups() != null) {
        for (Group group : contactGroup.getGroups()) {
            getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
        }
    }
    if (contactGroup.getOwners() != null) {
        for (Owner owner : contactGroup.getOwners()) {
            getPerunBl().getOwnersManagerBl().checkOwnerExists(sess, owner);
        }
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Owner(cz.metacentrum.perun.core.api.Owner) RichUser(cz.metacentrum.perun.core.api.RichUser)

Example 3 with Owner

use of cz.metacentrum.perun.core.api.Owner in project perun by CESNET.

the class FacilitiesManagerImpl method mergeContactGroups.

/**
	 * Take list of contact groups and merged them.
	 *
	 * Merge means:
	 * If two groups are from the same facility with the same contactName join
	 * them to the one with groups, owners and users from both.
	 *
	 * @param notMergedContactGroups list of groups to merge
	 * @return list of merged contact groups
	 */
private List<ContactGroup> mergeContactGroups(List<ContactGroup> notMergedContactGroups) {
    List<ContactGroup> mergedContactGroups = new ArrayList<>();
    while (!notMergedContactGroups.isEmpty()) {
        ContactGroup contactGroup = new ContactGroup();
        Iterator<ContactGroup> contactGroupIter = notMergedContactGroups.iterator();
        boolean first = true;
        while (contactGroupIter.hasNext()) {
            if (first) {
                contactGroup = contactGroupIter.next();
                if (contactGroup.getGroups() == null)
                    contactGroup.setGroups(new ArrayList<Group>());
                if (contactGroup.getOwners() == null)
                    contactGroup.setOwners(new ArrayList<Owner>());
                if (contactGroup.getUsers() == null)
                    contactGroup.setUsers(new ArrayList<RichUser>());
                first = false;
            } else {
                ContactGroup cp = contactGroupIter.next();
                //if same facility and same name merge them
                if (contactGroup.equalsGroup(cp)) {
                    List<Group> groups = new ArrayList<>();
                    groups.addAll(contactGroup.getGroups());
                    groups.addAll(cp.getGroups());
                    contactGroup.setGroups(groups);
                    List<Owner> owners = new ArrayList<>();
                    owners.addAll(contactGroup.getOwners());
                    owners.addAll(cp.getOwners());
                    contactGroup.setOwners(owners);
                    List<RichUser> users = new ArrayList<>();
                    users.addAll(contactGroup.getUsers());
                    users.addAll(cp.getUsers());
                    contactGroup.setUsers(users);
                // if not, skip this one for another round
                } else
                    continue;
            }
            //remove used groups of contacts
            contactGroupIter.remove();
        }
        mergedContactGroups.add(contactGroup);
    }
    return mergedContactGroups;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Owner(cz.metacentrum.perun.core.api.Owner) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup)

Example 4 with Owner

use of cz.metacentrum.perun.core.api.Owner in project perun by CESNET.

the class ExecServiceDaoTest method setUp.

@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
    try {
        perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
    } catch (InternalErrorException e) {
        log.error(e.toString());
    }
    jdbcTemplate = new JdbcPerunTemplate(dataSource);
    // Test Owner
    int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
    testOwner = new Owner();
    testOwner.setContact("Call me babe");
    testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
    testOwner.setType(OwnerType.technical);
    testOwner.setId(newOwnerId);
    jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
    // Test Service #1
    testService1 = new Service();
    testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
    // Test Service #2
    testService2 = new Service();
    testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
    testService1.setId(servicesManager.createService(perunSession, testService1).getId());
    testService2.setId(servicesManager.createService(perunSession, testService2).getId());
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Owner(cz.metacentrum.perun.core.api.Owner) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Before(org.junit.Before)

Example 5 with Owner

use of cz.metacentrum.perun.core.api.Owner in project perun by CESNET.

the class ExecServiceDenialDaoTest method setUp.

@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
    perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
    jdbcTemplate = new JdbcPerunTemplate(dataSource);
    // Test Owner
    int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
    testOwner = new Owner();
    testOwner.setContact("Call me babe");
    testOwner.setType(OwnerType.technical);
    testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
    testOwner.setId(newOwnerId);
    jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
    // Test Service #1
    testService1 = new Service();
    testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
    // Test Service #2
    testService2 = new Service();
    testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
    testService1.setId(servicesManager.createService(perunSession, testService1).getId());
    testService2.setId(servicesManager.createService(perunSession, testService2).getId());
    // Testing Destination #1
    testDestinationId1 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
    jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId1, "test.destination." + testDestinationId1);
    // Testing Destination #2
    testDestinationId2 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
    jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId2, "test.destination." + testDestinationId2);
    // Testing Facility #1
    testFacilityId1 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
    jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId1, "Cluster_" + testFacilityId1);
    // Testing Facility #2
    testFacilityId2 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
    jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId2, "Cluster_" + testFacilityId2);
    // Test ExecService #1 (Parent:testService1)
    testExecService1 = new ExecService();
    testExecService1.setDefaultDelay(1);
    testExecService1.setDefaultRecurrence(1);
    testExecService1.setEnabled(true);
    testExecService1.setService(testService1);
    testExecService1.setScript("/hellish/test/script");
    testExecService1.setExecServiceType(ExecServiceType.GENERATE);
    try {
        testExecService1.setId(execServiceDao.insertExecService(testExecService1));
    } catch (InternalErrorException e) {
        log.error(e.toString(), e);
    }
    // Test ExecService #2 (Parent:testService1)
    testExecService2 = new ExecService();
    testExecService2.setDefaultDelay(2);
    testExecService2.setDefaultRecurrence(2);
    testExecService2.setEnabled(true);
    testExecService2.setService(testService2);
    testExecService2.setScript("/hellish/test/script2");
    testExecService2.setExecServiceType(ExecServiceType.SEND);
    try {
        testExecService2.setId(execServiceDao.insertExecService(testExecService2));
    } catch (InternalErrorException e) {
        log.error(e.toString(), e);
    }
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Owner(cz.metacentrum.perun.core.api.Owner) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Before(org.junit.Before)

Aggregations

Owner (cz.metacentrum.perun.core.api.Owner)21 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)6 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)5 Facility (cz.metacentrum.perun.core.api.Facility)5 Group (cz.metacentrum.perun.core.api.Group)5 RichUser (cz.metacentrum.perun.core.api.RichUser)5 PerunClient (cz.metacentrum.perun.core.api.PerunClient)4 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)4 Service (cz.metacentrum.perun.core.api.Service)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 Before (org.junit.Before)4 JdbcPerunTemplate (org.springframework.jdbc.core.JdbcPerunTemplate)4 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)3 EnrichedFacility (cz.metacentrum.perun.core.api.EnrichedFacility)3 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)3 Resource (cz.metacentrum.perun.core.api.Resource)2 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 BanRemovedForFacility (cz.metacentrum.perun.audit.events.FacilityManagerEvents.BanRemovedForFacility)1