Search in sources :

Example 1 with DestinationNotExistsException

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

the class ServicesManagerBlImpl method addDestinationEvenIfAlreadyExists.

private Destination addDestinationEvenIfAlreadyExists(PerunSession sess, Service service, Facility facility, Destination destination) throws InternalErrorException {
    if (!getServicesManagerImpl().destinationExists(sess, destination)) {
        try {
            //Try to get the destination without id
            destination = getServicesManagerImpl().getDestination(sess, destination.getDestination(), destination.getType());
        } catch (DestinationNotExistsException ex) {
            try {
                destination = createDestination(sess, destination);
            } catch (DestinationExistsException e) {
                //This is ok, destination already exists so take it from DB
                try {
                    destination = getServicesManagerImpl().getDestination(sess, destination.getDestination(), destination.getType());
                } catch (DestinationNotExistsException exep) {
                    throw new ConsistencyErrorException("Destination seems to exists and not exists in the same time. There is some other problem." + exep);
                }
            }
        }
    }
    //if destination is already assigned, do not add message to the log and only return it back
    if (getServicesManagerImpl().destinationExists(sess, service, facility, destination))
        return destination;
    getServicesManagerImpl().addDestination(sess, service, facility, destination);
    getPerunBl().getAuditer().log(sess, "{} added to {} and {}.", destination, service, facility);
    return destination;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) DestinationNotExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationNotExistsException) DestinationExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationExistsException)

Example 2 with DestinationNotExistsException

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

the class ServicesManagerBlImpl method addDestination.

public Destination addDestination(PerunSession sess, Service service, Facility facility, Destination destination) throws InternalErrorException, DestinationAlreadyAssignedException {
    if (!getServicesManagerImpl().destinationExists(sess, destination)) {
        try {
            //Try to get the destination without id
            destination = getServicesManagerImpl().getDestination(sess, destination.getDestination(), destination.getType());
        } catch (DestinationNotExistsException ex) {
            try {
                destination = createDestination(sess, destination);
            } catch (DestinationExistsException e) {
                throw new ConsistencyErrorException(e);
            }
        }
    }
    if (getServicesManagerImpl().destinationExists(sess, service, facility, destination))
        throw new DestinationAlreadyAssignedException(destination);
    getServicesManagerImpl().addDestination(sess, service, facility, destination);
    getPerunBl().getAuditer().log(sess, "{} added to {} and {}.", destination, service, facility);
    return destination;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) DestinationNotExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationNotExistsException) DestinationExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationExistsException) DestinationAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.DestinationAlreadyAssignedException)

Example 3 with DestinationNotExistsException

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

the class ServicesManagerBlImpl method addDestination.

public Destination addDestination(PerunSession perunSession, List<Service> services, Facility facility, Destination destination) throws InternalErrorException, DestinationAlreadyAssignedException {
    if (!getServicesManagerImpl().destinationExists(perunSession, destination)) {
        try {
            //Try to get the destination without id
            destination = getServicesManagerImpl().getDestination(perunSession, destination.getDestination(), destination.getType());
        } catch (DestinationNotExistsException ex) {
            try {
                destination = createDestination(perunSession, destination);
            } catch (DestinationExistsException e) {
                throw new ConsistencyErrorException(e);
            }
        }
    }
    for (Service s : services) {
        if (!getServicesManagerImpl().destinationExists(perunSession, s, facility, destination)) {
            getServicesManagerImpl().addDestination(perunSession, s, facility, destination);
            getPerunBl().getAuditer().log(perunSession, "{} added to {} and {}.", destination, s, facility);
        }
    }
    return destination;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) DestinationNotExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationNotExistsException) Service(cz.metacentrum.perun.core.api.Service) DestinationExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationExistsException)

Example 4 with DestinationNotExistsException

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

the class ServicesManagerBlImpl method removeDestination.

public void removeDestination(PerunSession sess, Service service, Facility facility, Destination destination) throws InternalErrorException, DestinationAlreadyRemovedException {
    if (!getServicesManagerImpl().destinationExists(sess, destination)) {
        try {
            //Try to get the destination without id
            destination = getServicesManagerImpl().getDestination(sess, destination.getDestination(), destination.getType());
        } catch (DestinationNotExistsException ex) {
            throw new DestinationAlreadyRemovedException(destination);
        }
    }
    getServicesManagerImpl().removeDestination(sess, service, facility, destination);
    //TODO remove destination from destination taable if is not used anymore
    getPerunBl().getAuditer().log(sess, "{} removed from {} and {}.", destination, service, facility);
}
Also used : DestinationNotExistsException(cz.metacentrum.perun.core.api.exceptions.DestinationNotExistsException) DestinationAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.DestinationAlreadyRemovedException)

Aggregations

DestinationNotExistsException (cz.metacentrum.perun.core.api.exceptions.DestinationNotExistsException)4 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)3 DestinationExistsException (cz.metacentrum.perun.core.api.exceptions.DestinationExistsException)3 Service (cz.metacentrum.perun.core.api.Service)1 DestinationAlreadyAssignedException (cz.metacentrum.perun.core.api.exceptions.DestinationAlreadyAssignedException)1 DestinationAlreadyRemovedException (cz.metacentrum.perun.core.api.exceptions.DestinationAlreadyRemovedException)1