Search in sources :

Example 1 with ApplicationMail

use of cz.metacentrum.perun.webgui.model.ApplicationMail in project perun by CESNET.

the class JsonErrorHandler method getText.

private static String getText(String errorName, PerunError error) {
    String pleaseRefresh = "<p>Try to <strong>refresh the browser</strong> window and retry.<br />If problem persist, please report it.";
    // RPC ERRORS
    if ("RpcException".equalsIgnoreCase(errorName)) {
        if ("UNCATCHED_EXCEPTION".equalsIgnoreCase(error.getType())) {
            return "Unknown error occurred. Please report it.";
        } else {
            return "Error in communication with server. " + pleaseRefresh;
        }
    } else if ("PrivilegeException".equalsIgnoreCase(errorName)) {
        return WidgetTranslation.INSTANCE.jsonClientNotAuthorizedMessage();
    } else if ("WrongAttributeAssignmentException".equalsIgnoreCase(errorName)) {
        return "You tried to set wrong attribute for entity. Please report this error.";
    } else if ("WrongAttributeValueException".equalsIgnoreCase(errorName)) {
        Attribute a = error.getAttribute();
        GeneralObject holder = error.getAttributeHolder();
        GeneralObject secondHolder = error.getAttributeHolderSecondary();
        String text = "Wrong value of attribute (value or format).<p>";
        if (holder != null) {
            if (!holder.getName().equalsIgnoreCase("undefined")) {
                text += "<strong>" + SafeHtmlUtils.fromString(holder.getObjectType()).asString() + ":</strong>&nbsp;" + SafeHtmlUtils.fromString(holder.getName()).asString() + "<br />";
            }
        }
        if (secondHolder != null) {
            if (!secondHolder.getName().equalsIgnoreCase("undefined")) {
                text += "<strong>" + SafeHtmlUtils.fromString(secondHolder.getObjectType()).asString() + ":</strong>&nbsp;" + SafeHtmlUtils.fromString(secondHolder.getName()).asString() + "<br />";
            }
        }
        if (a != null) {
            String attrName = SafeHtmlUtils.fromString(a.getDisplayName()).asString();
            String attrValue = SafeHtmlUtils.fromString(a.getValue()).asString();
            text += "<strong>Attribute:&nbsp;</strong>" + attrName + "<br /><strong>Value:&nbsp;</strong>" + attrValue;
        } else {
            text += "<i>Attribute is null</i>";
        }
        return text;
    } else if ("WrongReferenceAttributeValueException".equalsIgnoreCase(errorName)) {
        String text = "Value of one of related attributes is incorrect.";
        Attribute a = error.getAttribute();
        Attribute a2 = error.getReferenceAttribute();
        if (a != null) {
            String attrName = SafeHtmlUtils.fromString(a.getDisplayName()).asString();
            String attrValue = SafeHtmlUtils.fromString(a.getValue()).asString();
            String entity = SafeHtmlUtils.fromString(a.getEntity()).asString();
            text += "<p><strong>Attribute&nbsp;1:</strong>&nbsp;" + attrName + " (" + entity + ")";
            text += "<br/><strong>Value&nbsp;1:</strong>&nbsp;" + attrValue;
        } else {
            text += "<p><i>Attribute 1 is null</i>";
        }
        if (a2 != null) {
            String attrName = SafeHtmlUtils.fromString(a2.getDisplayName()).asString();
            String attrValue = SafeHtmlUtils.fromString(a2.getValue()).asString();
            String entity = SafeHtmlUtils.fromString(a2.getEntity()).asString();
            text += "<p><strong>Attribute&nbsp;2:</strong>&nbsp;" + attrName + " (" + entity + ")";
            text += "<br/><strong>Value&nbsp;2:</strong>&nbsp;" + attrValue;
        } else {
            text += "<p><i>Attribute 2 is null</i>";
        }
        return text;
    } else if ("AttributeNotExistsException".equalsIgnoreCase(errorName)) {
        Attribute a = error.getAttribute();
        if (a != null) {
            return "Attribute definition for attribute <i>" + SafeHtmlUtils.fromString(a.getName()).asString() + "</i> doesn't exist.";
        } else {
            return "Attribute definition for attribute <i>null</i> doesn't exist.";
        }
    } else if ("AttributeAlreadyMarkedUniqueException".equalsIgnoreCase(errorName)) {
        Attribute a = error.getAttribute();
        if (a != null) {
            return "Attribute definition of <i>" + SafeHtmlUtils.fromString(a.getName()).asString() + "</i> is already marked as UNIQUE.";
        } else {
            return "Attribute definition of <i>null</i> is already marked as UNIQUE.";
        }
    // ALL CABINET EXCEPTIONS
    } else if ("CabinetException".equalsIgnoreCase(errorName)) {
        String text = "";
        if (error.getType().equalsIgnoreCase("NO_IDENTITY_FOR_PUBLICATION_SYSTEM")) {
            text = "You don't have registered identity in Perun related to selected publication system.<p>Please visit <a target=\"new\" href=\"" + Utils.getIdentityConsolidatorLink(false) + "\">identity consolidator</a> to add more identities.";
        } else if (error.getType().equalsIgnoreCase("THANKS_ALREADY_EXISTS")) {
            text = "Acknowledgement is already added.";
        }
        return text;
    // STANDARD ERRORS ALPHABETICALLY
    } else if ("AlreadyAdminException".equalsIgnoreCase(errorName)) {
        String text = "";
        if (error.getUser() != null) {
            text = SafeHtmlUtils.fromString(error.getUser().getFullName()).asString();
        } else {
            text = "User";
        }
        if (error.getVo() != null) {
            text += " is already manager of VO: " + SafeHtmlUtils.fromString(error.getVo().getName()).asString();
        } else if (error.getFacility() != null) {
            text += " is already manager of Facility: " + SafeHtmlUtils.fromString(error.getFacility().getName()).asString();
        } else if (error.getGroup() != null) {
            text += " is already manager of Group: " + SafeHtmlUtils.fromString(error.getGroup().getName()).asString();
        } else if (error.getSecurityTeam() != null) {
            text += " is already manager of SecurityTeam: " + SafeHtmlUtils.fromString(error.getSecurityTeam().getName()).asString();
        }
        return text;
    } else if ("AlreadyMemberException".equalsIgnoreCase(errorName)) {
        // TODO - this exception must contain user first !!
        return "User is already member of VO / Group.";
    } else if ("AlreadyProcessingException".equalsIgnoreCase(errorName)) {
        return "<p>" + error.getErrorInfo() + "<p>It was probably started by on of the other administrators. If this problem persist, please contact support.";
    } else if ("AlreadyReservedLoginException".equalsIgnoreCase(errorName)) {
        String text = "";
        if (error.getLogin() != null) {
            text += "Login: " + SafeHtmlUtils.fromString(error.getLogin()).asString();
            if (error.getNamespace() != null) {
                text += " in namespace: " + SafeHtmlUtils.fromString(error.getNamespace()).asString() + " is already reserved.";
            } else {
                text += " is already reserved.";
            }
        } else {
            text += "Login";
            if (error.getNamespace() != null) {
                text += " in namespace: " + SafeHtmlUtils.fromString(error.getNamespace()).asString() + " is already reserved.";
            } else {
                text += " is already reserved in selected namespace.";
            }
        }
        return text;
    } else if ("AttributeAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        if (error.getAttribute() != null) {
            return "Attribute <i>" + SafeHtmlUtils.fromString(error.getAttribute().getDisplayName()).asString() + "</i> is already set as required by service.";
        } else {
            return "Attribute is already set as required by service.";
        }
    } else if ("AttributeDefinitionExistsException".equalsIgnoreCase(errorName)) {
        return "Same attribute definition already exists in Perun.";
    } else if ("AttributeNotAssignedException".equalsIgnoreCase(errorName)) {
        if (error.getAttribute() != null) {
            return "Attribute <i>" + SafeHtmlUtils.fromString(error.getAttribute().getDisplayName()).asString() + "</i> is already NOT required by service.";
        } else {
            return "Attribute is already NOT required by service.";
        }
    } else if ("AttributeNotExistsException".equalsIgnoreCase(errorName)) {
        // FIXME - attribute object inside is never used, but has good description
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("AttributeValueException".equalsIgnoreCase(errorName)) {
        // FIXME - core always uses extensions of this exception
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("ApplicationNotCreatedException".equalsIgnoreCase(errorName)) {
        return ApplicationMessages.INSTANCE.errorWhileCreatingApplicationMessage();
    } else if ("CandidateNotExistsException".equalsIgnoreCase(errorName)) {
        return "Candidate for VO membership doesn't exists in external source.";
    } else if ("ClusterNotExistsException".equalsIgnoreCase(errorName)) {
        return "Facility is not of type <i>cluster</i> or <i>virtual cluster</i>";
    } else if ("ConsistencyErrorException".equalsIgnoreCase(errorName)) {
        return "Your operation can't be completed. There seems to be a problem with DB consistency, please report this error.";
    } else if ("DestinationAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        if (error.getDestination() != null) {
            return "Destination <i>" + SafeHtmlUtils.fromString(error.getDestination().getDestination()).asString() + "</i> already exists for facility/service.";
        } else {
            return "Same destination already exists for facility/service combination.";
        }
    } else if ("DestinationAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        if (error.getDestination() != null) {
            return "Destination <i>" + SafeHtmlUtils.fromString(error.getDestination().getDestination()).asString() + "</i> already removed for facility/service.";
        } else {
            return "Destination is already removed from facility/service combination.";
        }
    } else if ("DestinationExistsException".equalsIgnoreCase(errorName)) {
        return "Same destination already exists.";
    } else if ("DestinationNotExistsException".equalsIgnoreCase(errorName)) {
        return "Destination of this name/id doesn't exists.";
    } else if ("DiacriticNotAllowedException".equalsIgnoreCase(errorName)) {
        // has meaningful info
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    // FIXME - ENTITY exceptions are always extended - we will use specific types
    } else if ("ExtendMembershipException".equalsIgnoreCase(errorName)) {
        String text = "Membership in VO can't be established or extended. ";
        if ("NOUSERLOA".equalsIgnoreCase(error.getReason())) {
            text += " User's IDP does not provide Level of Assurance but VO requires it.";
        } else if ("INSUFFICIENTLOA".equalsIgnoreCase(error.getReason())) {
            text += " User's Level of Assurance is not sufficient for VO.";
        } else if ("INSUFFICIENTLOAFOREXTENSION".equalsIgnoreCase(error.getReason())) {
            text += " User's Level of Assurance is not sufficient for VO.";
        } else if ("OUTSIDEEXTENSIONPERIOD".equalsIgnoreCase(error.getReason())) {
            text += " It can be done usually in short time before and after membership expiration.";
        }
        return text;
    } else if ("ExtSourceAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        if (error.getExtSource() != null) {
            return "Same external source is already assigned to your VO." + "<p><strong>Name:</strong> " + SafeHtmlUtils.fromString(error.getExtSource().getName()).asString() + "</br>" + "<strong>Type:</strong> " + SafeHtmlUtils.fromString(error.getExtSource().getType()).asString();
        } else {
            return "Same external source is already assigned to your VO.";
        }
    } else if ("ExtSourceAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        if (error.getExtSource() != null) {
            return "Same external source was already removed from your VO." + "<p><strong>Name:</strong> " + SafeHtmlUtils.fromString(error.getExtSource().getName()).asString() + "</br>" + "<strong>Type:</strong> " + SafeHtmlUtils.fromString(error.getExtSource().getType()).asString();
        } else {
            return "Same external source was already removed from your VO.";
        }
    } else if ("ExtSourceExistsException".equalsIgnoreCase(errorName)) {
        if (error.getExtSource() != null) {
            return "Same external source already exists." + "<p><strong>Name:</strong> " + SafeHtmlUtils.fromString(error.getExtSource().getName()).asString() + "</br>" + "<strong>Type:</strong> " + SafeHtmlUtils.fromString(error.getExtSource().getType()).asString();
        } else {
            return "Same external source already exists.";
        }
    } else if ("ExtSourceInUseException".equalsIgnoreCase(errorName)) {
        // TODO - ext source not in exception
        return "Selected external source is currently in use and can't be removed from VO or deleted.";
    } else if ("ExtSourceNotAssignedException".equalsIgnoreCase(errorName)) {
        // TODO - ext source not in exception
        return "Selected external source is not assigned to your VO and can't be removed.";
    } else if ("ExtSourceNotExistsException".equalsIgnoreCase(errorName)) {
        // TODO - better text ?? + ext source not in exception
        return "External source of this ID or name doesn't exists.";
    } else if ("ExtSourceUnsupportedOperationException".equalsIgnoreCase(errorName)) {
        // TODO - probably is never thrown to GUI ??
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("FacilityAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Facility of the same name and type was already deleted.";
    } else if ("FacilityExistsException".equalsIgnoreCase(errorName)) {
        return "Facility of the same name and type already exists.";
    } else if ("FacilityNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested Facility (by id or name/type) doesn't exists.";
    } else if ("FacilityNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested Facility (by id or name/type) doesn't exists.";
    } else if ("GroupAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        Group g = error.getGroup();
        if (g != null) {
            return "Group: " + SafeHtmlUtils.fromString(g.getName()).asString() + " is already assigned to Resource.";
        } else {
            return "Group is already assigned to Resource.";
        }
    } else if ("GroupExistsException".equalsIgnoreCase(errorName)) {
        return "Group with same name already exists in your VO. Group names must be unique in VO.";
    } else if ("GroupAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same group was already removed from your VO/Group.";
    } else if ("GroupAlreadyRemovedFromResourceException".equalsIgnoreCase(errorName)) {
        return "Same group was already removed from resource.";
    } else if ("GroupNotDefinedOnResourceException".equalsIgnoreCase(errorName)) {
        return "Group is not assigned to Resource and therefore can't be removed from it.";
    } else if ("GroupNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested Group (by id or name/vo) doesn't exists.";
    } else if ("GroupResourceMismatchException".equalsIgnoreCase(errorName)) {
        return "Group and Resource doesn't belong to the same VO.";
    } else if ("GroupMoveNotAllowedException".equalsIgnoreCase(errorName)) {
        Group movingGroup = error.getMovingGroup();
        Group destinationGroup = error.getDestinationGroup();
        String movingGroupName = (movingGroup != null) ? ("<b>" + SafeHtmlUtils.fromString(movingGroup.getName()).asString() + "</b>") : "Group";
        String destinationGroupName = (destinationGroup != null) ? ("under <b>" + SafeHtmlUtils.fromString(destinationGroup.getName()).asString() + "</b>") : " to top-level";
        return movingGroupName + " can't be moved " + destinationGroupName + ".<p>Reason: " + SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("GroupRelationAlreadyExists".equalsIgnoreCase(errorName)) {
        return "Groups are already in a relation. Please refresh your view/table to see current state.";
    } else if ("GroupRelationCannotBeRemoved".equalsIgnoreCase(errorName)) {
        return "Relation can't be removed, since groups are in a direct hierarchy. If necessary, please delete the sub-group.";
    } else if ("GroupRelationDoesNotExist".equalsIgnoreCase(errorName)) {
        return "Groups are not in a relation. Please refresh your view/table to see current state.";
    } else if ("GroupRelationNotAllowed".equalsIgnoreCase(errorName)) {
        return "You can't add groups to relation. It would create a cycle.";
    } else if ("GroupSynchronizationAlreadyRunningException".equalsIgnoreCase(errorName)) {
        return "Can't start group synchronization between Perun and external source, because it's already running.";
    } else if ("HostAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same host was already removed from facility.";
    } else if ("HostExistsException".equalsIgnoreCase(errorName)) {
        // TODO - Facility object in this exception would really help
        return "Either same host already exists on Facility or you are trying to add more than one host to (v)host Facility type (can have only one).";
    } else if ("HostNotExistsException".equalsIgnoreCase(errorName)) {
        // TODO - host object is not filled on core side
        return "Requested Host (by name) doesn't exists.";
    } else if ("IllegalArgumentException".equalsIgnoreCase(errorName)) {
        // FIXME - is this generic error ??
        return "Your operation can't be completed. " + SafeHtmlUtils.fromString(error.getErrorInfo()).asString() + " Please report this error.";
    } else if ("InternalErrorException".equalsIgnoreCase(errorName)) {
        // FIXME - is this generic error ??
        return "Your operation can't be completed. Internal error occurred. Please report this error.";
    } else if ("LoginNotExistsException".equalsIgnoreCase(errorName)) {
        // TODO - login + namespace should be in exception
        return "User doesn't have login set for selected namespace.";
    } else if ("MaxSizeExceededException".equalsIgnoreCase(errorName)) {
        // has meaningfull message
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("MemberAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Member was already removed from group/VO.";
    } else if ("MemberNotAdminException".equalsIgnoreCase(errorName)) {
        // FIXME - will be removed in favor of UserNotAdminException
        return "Can't remove user from administrators (user is not an administrator).";
    } else if ("MemberNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested member (by id or ues) doesn't exists.";
    } else if ("MemberNotValidYetException".equalsIgnoreCase(errorName)) {
        return "Can't disable membership for VO member if not valid yet.";
    } else if ("MembershipMismatchException".equalsIgnoreCase(errorName)) {
        return "Can't add member to group. They are from different VOs.";
    } else if ("MessageParsingFailException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("ModuleNotExistsException".equalsIgnoreCase(errorName)) {
        return "Module for virtual attribute doesn't exists. Please report this error.";
    } else if ("NotGroupMemberException".equalsIgnoreCase(errorName)) {
        return "Can't remove user from group. User already isn't group member.";
    } else if ("NotSpecificUserExpectedException".equalsIgnoreCase(errorName)) {
        return "Operation can't be done. Expected person type of user, but service type was provided instead.";
    } else if ("NumberNotInRangeException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("NumbersNotAllowedException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("OwnerAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        return "Can't add owner to Facility. Owner is already assigned.";
    } else if ("OwnerAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Can't remove owner from Facility. Owner is already removed.";
    } else if ("OwnerNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested Owner (by id) doesn't exists.";
    } else if ("ParentGroupNotExistsException".equalsIgnoreCase(errorName)) {
        return "Group doesn't have parent group.";
    } else if ("PasswordChangeFailedException".equalsIgnoreCase(errorName)) {
        return "Changing password failed due to an internal error. Please report it.";
    } else if ("PasswordCreationFailedException".equalsIgnoreCase(errorName)) {
        return "Password creation failed due to an internal error. Please report it.";
    } else if ("PasswordDeletionFailedException".equalsIgnoreCase(errorName)) {
        return "Password deletion failed due to an internal error. Please report it.";
    } else if ("PasswordDoesntMatchException".equalsIgnoreCase(errorName)) {
        return "Can't set new password. Old password doesn't match.";
    } else if ("PasswordResetMailNotExistsException".equalsIgnoreCase(errorName)) {
        return "User doesn't have the chosen email attribute set. Choose different attribute.";
    } else if ("PasswordStrengthFailedException".equalsIgnoreCase(errorName)) {
        return "Used password doesn't match required strength constraints.";
    } else if ("PasswordOperationTimeoutException".equalsIgnoreCase(errorName)) {
        return "Operation with password exceeded expected time limit.";
    } else if ("RelationExistsException".equalsIgnoreCase(errorName)) {
        // FIXME - better text on core side
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("RelationNotExistsException".equalsIgnoreCase(errorName)) {
        // FIXME - better text on core side
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("ResourceAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same resource was already removed from facility (deleted).";
    } else if ("ResourceExistsException".equalsIgnoreCase(errorName)) {
        return "Resource with same name \"" + SafeHtmlUtils.fromString(error.getResource().getName()).asString() + "\" already exists with id=" + SafeHtmlUtils.fromString(error.getResource().getId() + "").asString() + ".";
    } else if ("ResourceNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested resource (by id) doesn't exists.";
    } else if ("ResourceTagAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        // FIXME - must contain also resource
        return "Same tag is already assigned to resource.";
    } else if ("ResourceTagNotAssignedException".equalsIgnoreCase(errorName)) {
        // FIXME - must contain also resource
        return "Tag is not assigned to resource.";
    } else if ("ResourceTagNotExistsException".equalsIgnoreCase(errorName)) {
        // FIXME - must contain also resource
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("SecurityTeamAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        if (error.getSecurityTeam() != null) {
            return "SecurityTeam <i>" + SafeHtmlUtils.fromString(error.getSecurityTeam().getName()).asString() + "</i> is already assigned to facility.";
        } else {
            return "Same SecurityTeam is already assigned to facility.";
        }
    } else if ("ServiceAlreadyAssignedException".equalsIgnoreCase(errorName)) {
        // FIXME - must contain also resource
        if (error.getService() != null) {
            return "Service " + SafeHtmlUtils.fromString(error.getService().getName()).asString() + " is already assigned to resource.";
        } else {
            return "Same service is already assigned to resource.";
        }
    } else if ("ServiceAlreadyBannedException".equalsIgnoreCase(errorName)) {
        if (error.getService() != null && error.getFacility() != null) {
            return "Service " + SafeHtmlUtils.fromString(error.getService().getName()).asString() + " is already banned on facility " + SafeHtmlUtils.fromString(error.getFacility().getName()).asString() + ".";
        } else {
            return "Same service is already banned on facility.";
        }
    } else if ("ServiceExistsException".equalsIgnoreCase(errorName)) {
        if (error.getService() != null) {
            return "Service " + SafeHtmlUtils.fromString(error.getService().getName()).asString() + " already exists in Perun. Choose different name.";
        } else {
            return "Service with same name already exists in Perun.";
        }
    } else if ("ServiceNotAssignedException".equalsIgnoreCase(errorName)) {
        // FIXME - must contain also resource
        if (error.getService() != null) {
            return "Service " + SafeHtmlUtils.fromString(error.getService().getName()).asString() + " is not assigned to resource.";
        } else {
            return "Service is not assigned to resource.";
        }
    } else if ("ServiceAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same service was already deleted.";
    } else if ("ServiceNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested service (by id or name) doesn't exists.";
    } else if ("ServicesPackageExistsException".equalsIgnoreCase(errorName)) {
        // TODO - we don't support service packages yet
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("ServiceAlreadyRemovedFromServicePackageException".equalsIgnoreCase(errorName)) {
        return "Same service was already removed from service package.";
    } else if ("ServiceAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same service was already deleted.";
    } else if ("SpecificUserExpectedException".equalsIgnoreCase(errorName)) {
        return "Operation can't be done. Expected specific type of user, but person type was provided instead.";
    } else if ("SpecificUserAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same specific user was already removed from user.";
    } else if ("SpecificUserOwnerAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same user was already removed from owners of specific user.";
    } else if ("SpecificUserMustHaveOwnerException".equalsIgnoreCase(errorName)) {
        return "Specific type user must have at least 1 person type user assigned, which is responsible for it.";
    } else if ("SpaceNotAllowedException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("SpecialCharsNotAllowedException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString() + " You can use only letters, numbers and spaces.";
    } else if ("SpecialCharsNotAllowedException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString() + " You can use only letters, numbers and spaces.";
    } else if ("SubGroupCannotBeRemovedException".equalsIgnoreCase(errorName)) {
        return "Subgroup can't be removed from resource. Only directly assigned groups can be removed.";
    } else if ("SubjectNotExistsException".equalsIgnoreCase(errorName)) {
        // FIXME - probably never thrown to GUI ?? + better exception text.
        return "Requested user by login in LDAP external source doesn't exists or more than one was found.";
    } else if ("UserExtSourceExistsException".equalsIgnoreCase(errorName)) {
        // TODO - user ext source object in exception
        return "Same user external identity already exists and is used by different user.";
    } else if ("UserExtSourceNotExistsException".equalsIgnoreCase(errorName)) {
        return "Requested user external identity doesn't exists.";
    } else if ("UserExtSourceAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Same user's external identity was already removed from him/her.";
    } else if ("UserNotAdminException".equalsIgnoreCase(errorName)) {
        // FIXME - add vo, group or facility !!
        return "Can't remove user from managers of VO/Group/Facility. User is not manager.";
    } else if ("UserNotExistsException".equalsIgnoreCase(errorName)) {
        // TODO - get user from exception
        return "Requested user (by id or external identity) doesn't exists.";
    } else if ("UserAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        // TODO - shoud contain user objects
        return "Same user was already deleted.";
    } else if ("VoExistsException".equalsIgnoreCase(errorName)) {
        return "VO with same name already exists. Please choose different name.";
    } else if ("VoNotExistsException".equalsIgnoreCase(errorName)) {
        // TODO - get vo from exception
        return "Requested VO (by id or name) doesn't exists.";
    } else if ("WrongModuleTypeException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("WrongRangeOfCountException".equalsIgnoreCase(errorName)) {
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("WrongPatternException".equalsIgnoreCase(errorName)) {
        // meaningful message
        return SafeHtmlUtils.fromString(error.getErrorInfo()).asString();
    } else if ("MissingRequiredDataException".equalsIgnoreCase(errorName)) {
        String result = "Your IDP doesn't provide all required data for this application form. Please contact your IDP to resolve this issue or log-in using different IDP.";
        String missingItems = "<p>";
        if (error.getFormItems() != null) {
            for (int i = 0; i < error.getFormItems().length(); i++) {
                missingItems += "<strong>Missing attribute: </strong>";
                missingItems += SafeHtmlUtils.fromString(error.getFormItems().get(i).getFormItem().getFederationAttribute()).asString();
                missingItems += "<br />";
            }
        }
        result += missingItems;
        return result;
    } else if ("RequestTimeout".equalsIgnoreCase(errorName)) {
        String result = "Your operation is still processing on server. Please refresh your view (table) to see, if it ended up successfully before trying again.";
        return result;
    } else if ("ApplicationMailAlreadyRemovedException".equalsIgnoreCase(errorName)) {
        return "Application mail was already removed.";
    } else if ("ApplicationMailNotExistsException".equalsIgnoreCase(errorName)) {
        ApplicationMail mail = error.getApplicationMail();
        if (mail != null)
            return "Application mail with template " + mail.getMailType() + " and id " + mail.getId() + " does not exist.";
        return "Application mail does not exist.";
    } else if ("ApplicationMailExistsException".equalsIgnoreCase(errorName)) {
        ApplicationMail mail = error.getApplicationMail();
        if (mail != null)
            return "Application mail with template " + mail.getMailType() + " and id " + mail.getId() + " already exists.";
        return "Application mail already exists.";
    }
    // default text
    return error.getErrorInfo();
}
Also used : Group(cz.metacentrum.perun.webgui.model.Group) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) JSONString(com.google.gwt.json.client.JSONString) ApplicationMail(cz.metacentrum.perun.webgui.model.ApplicationMail)

Example 2 with ApplicationMail

use of cz.metacentrum.perun.webgui.model.ApplicationMail in project perun by CESNET.

the class MailsTabItem method draw.

public Widget draw() {
    final GetApplicationMails mailsRequest;
    String title = "";
    if (group != null) {
        title = group.getName();
        entity = PerunEntity.GROUP;
        entityId = group.getId();
        mailsRequest = new GetApplicationMails(entity, group.getId());
    } else {
        title = vo.getName();
        entityId = vo.getId();
        mailsRequest = new GetApplicationMails(entity, vo.getId());
    }
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(title) + ": " + "Email notifications");
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    firstTabPanel.add(menu);
    firstTabPanel.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    // add button
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMail(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateMailTabItem(vo, group, form));
        }
    }));
    // remove button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMail());
    menu.addWidget(removeButton);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
            String text = "Following mail definitions will be removed and users won't receive them anymore.";
            UiElements.showDeleteConfirm(list, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    for (int i = 0; i < list.size(); i++) {
                        if (i != list.size() - 1) {
                            DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.deleteMail(list.get(i).getId(), entityId);
                        } else {
                            // refresh table on last call
                            DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(mailsRequest)));
                            request.deleteMail(list.get(i).getId(), entityId);
                        }
                    }
                }
            });
        }
    });
    // enable button
    CustomButton enableButton = TabMenu.getPredefinedButton(ButtonType.ENABLE, ButtonTranslation.INSTANCE.enableMail(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
                request.setEnabled(list, true);
            }
        }
    });
    menu.addWidget(enableButton);
    // disable button
    CustomButton disableButton = TabMenu.getPredefinedButton(ButtonType.DISABLE, ButtonTranslation.INSTANCE.disableMail(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
                request.setEnabled(list, false);
            }
        }
    });
    menu.addWidget(disableButton);
    menu.addWidget(new CustomButton(ButtonTranslation.INSTANCE.mailFooterButton() + "…", ButtonTranslation.INSTANCE.editMailFooter(), SmallIcons.INSTANCE.emailIcon(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (group == null) {
                session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(vo));
            } else {
                session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(group));
            }
        }
    }));
    CustomButton copy;
    if (group == null) {
        copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromVoButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromVo(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(voId, 0));
            }
        });
    } else {
        copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromGroupButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromGroup(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(group.getVoId(), groupId));
            }
        });
    }
    menu.addWidget(copy);
    // TABLE
    CellTable<ApplicationMail> table = mailsRequest.getTable(new FieldUpdater<ApplicationMail, String>() {

        public void update(int index, ApplicationMail appMail, String value) {
            session.getTabManager().addTabToCurrentTab(new EditMailTabItem(appMail));
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    removeButton.setEnabled(false);
    enableButton.setEnabled(false);
    disableButton.setEnabled(false);
    JsonUtils.addTableManagedButton(mailsRequest, table, removeButton);
    JsonUtils.addTableManagedButton(mailsRequest, table, enableButton);
    JsonUtils.addTableManagedButton(mailsRequest, table, disableButton);
    session.getUiElements().resizePerunTable(sp, 100);
    firstTabPanel.add(sp);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) SetSendingEnabled(cz.metacentrum.perun.webgui.json.registrarManager.SetSendingEnabled) GetApplicationMails(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationMails) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) DeleteApplicationMail(cz.metacentrum.perun.webgui.json.registrarManager.DeleteApplicationMail) ApplicationMail(cz.metacentrum.perun.webgui.model.ApplicationMail) DeleteApplicationMail(cz.metacentrum.perun.webgui.json.registrarManager.DeleteApplicationMail)

Example 3 with ApplicationMail

use of cz.metacentrum.perun.webgui.model.ApplicationMail in project perun by CESNET.

the class SetSendingEnabled method prepareJSONObject.

/**
 * Prepares a JSON object.
 * @return JSONObject - the whole query
 */
private JSONObject prepareJSONObject() {
    JSONArray mails = new JSONArray();
    int i = 0;
    for (ApplicationMail appMail : appMails) {
        JSONObject mail = new JSONObject();
        // update send
        mail.put("send", JSONBoolean.getInstance(appMail.isSend()));
        JSONObject mailTexts = new JSONObject();
        // update texts
        MailText mt = appMail.getMessage("en");
        mailTexts.put("en", new JSONObject(mt));
        if (!Utils.getNativeLanguage().isEmpty()) {
            MailText mt2 = appMail.getMessage(Utils.getNativeLanguage().get(0));
            mailTexts.put(Utils.getNativeLanguage().get(0), new JSONObject(mt2));
        }
        mail.put("message", mailTexts);
        // sending other values just for sure
        mail.put("id", new JSONNumber(appMail.getId()));
        mail.put("appType", new JSONString(appMail.getAppType()));
        mail.put("mailType", new JSONString(appMail.getMailType()));
        mail.put("formId", new JSONNumber(appMail.getFormId()));
        // put in list
        mails.set(i, mail);
        i++;
    }
    JSONObject request = new JSONObject();
    request.put("mails", mails);
    if (enabled == true) {
        request.put("enabled", new JSONNumber(1));
    } else {
        request.put("enabled", new JSONNumber(0));
    }
    return request;
}
Also used : MailText(cz.metacentrum.perun.webgui.model.MailText) ApplicationMail(cz.metacentrum.perun.webgui.model.ApplicationMail)

Example 4 with ApplicationMail

use of cz.metacentrum.perun.webgui.model.ApplicationMail in project perun by CESNET.

the class GetApplicationMails method getTable.

/**
 * Returns just the celltable
 * @return
 */
public CellTable<ApplicationMail> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<ApplicationMail>(list);
    // Cell table
    table = new PerunTable<ApplicationMail>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<ApplicationMail> columnSortHandler = new ListHandler<ApplicationMail>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<ApplicationMail>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    if (PerunEntity.VIRTUAL_ORGANIZATION.equals(entity)) {
        loaderImage.setEmptyResultMessage("No mail notifications found for this VO.");
    } else if (PerunEntity.GROUP.equals(entity)) {
        loaderImage.setEmptyResultMessage("No mail notifications found for this group.");
    }
    // columns
    if (checkable) {
        table.addCheckBoxColumn();
    }
    table.addIdColumn("E-mail ID", tableFieldUpdater, 90);
    // MAIL TYPE COLUMN
    Column<ApplicationMail, String> mailTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<ApplicationMail, String>() {

        public String getValue(ApplicationMail object) {
            return ApplicationMail.getTranslatedMailType(object.getMailType());
        }
    }, tableFieldUpdater);
    mailTypeColumn.setSortable(true);
    columnSortHandler.setComparator(mailTypeColumn, new Comparator<ApplicationMail>() {

        public int compare(ApplicationMail arg0, ApplicationMail arg1) {
            return (ApplicationMail.getTranslatedMailType(arg0.getMailType())).compareToIgnoreCase(ApplicationMail.getTranslatedMailType(arg1.getMailType()));
        }
    });
    table.addColumn(mailTypeColumn, "E-mail type");
    // APPLICATION TYPE COLUMN
    Column<ApplicationMail, String> appTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<ApplicationMail, String>() {

        public String getValue(ApplicationMail object) {
            return Application.getTranslatedType(object.getAppType());
        }
    }, tableFieldUpdater);
    appTypeColumn.setSortable(true);
    columnSortHandler.setComparator(appTypeColumn, new Comparator<ApplicationMail>() {

        public int compare(ApplicationMail arg0, ApplicationMail arg1) {
            return (Application.getTranslatedType(arg0.getAppType())).compareToIgnoreCase(Application.getTranslatedType(arg1.getAppType()));
        }
    });
    table.addColumn(appTypeColumn, "Application type");
    // ENABLED COLUMN
    Column<ApplicationMail, Boolean> enabledColumn = new Column<ApplicationMail, Boolean>(new WhetherEnabledCell()) {

        @Override
        public Boolean getValue(ApplicationMail object) {
            return object.isSend();
        }
    };
    enabledColumn.setSortable(true);
    columnSortHandler.setComparator(enabledColumn, new Comparator<ApplicationMail>() {

        public int compare(ApplicationMail arg0, ApplicationMail arg1) {
            if (arg0.isSend() == arg1.isSend())
                return 0;
            if (arg0.isSend() == true)
                return -1;
            return 1;
        }
    });
    table.addColumn(enabledColumn, "Sending enabled");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) WhetherEnabledCell(cz.metacentrum.perun.webgui.widgets.cells.WhetherEnabledCell) Column(com.google.gwt.user.cellview.client.Column) ApplicationMail(cz.metacentrum.perun.webgui.model.ApplicationMail)

Aggregations

ApplicationMail (cz.metacentrum.perun.webgui.model.ApplicationMail)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JSONString (com.google.gwt.json.client.JSONString)1 Column (com.google.gwt.user.cellview.client.Column)1 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)1 DeleteApplicationMail (cz.metacentrum.perun.webgui.json.registrarManager.DeleteApplicationMail)1 GetApplicationMails (cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationMails)1 SetSendingEnabled (cz.metacentrum.perun.webgui.json.registrarManager.SetSendingEnabled)1 Attribute (cz.metacentrum.perun.webgui.model.Attribute)1 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)1 Group (cz.metacentrum.perun.webgui.model.Group)1 MailText (cz.metacentrum.perun.webgui.model.MailText)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 WhetherEnabledCell (cz.metacentrum.perun.webgui.widgets.cells.WhetherEnabledCell)1 ArrayList (java.util.ArrayList)1