/*
 * Copyright 2016 Crown Copyright
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package stroom.entity.shared;

import stroom.util.shared.ModelStringUtil;

public class PermissionException extends EntityServiceException {
    private static final long serialVersionUID = -7671344466028839328L;

    public PermissionException() {
        // Default constructor necessary for GWT serialisation.
    }

    public PermissionException(final String message) {
        super(message);
    }

    public PermissionException(final String securedType, final String name, final String methodName,
            final String message) {
        super(message, null, false);
        if (securedType != null || name != null || methodName != null) {
            setDetail(ModelStringUtil.toDisplayValue(securedType) + (name == null ? "" : " - " + name)
                    + (methodName == null ? "" : " - " + methodName));
        }
    }

    public static PermissionException createLoginRequiredException(final String name,
            final String methodName) {
        return new PermissionException(null, name, methodName, "User must be logged in to call service");
    }

    public static PermissionException createAppPermissionRequiredException(final String permission,
                                                                           final String methodName) {
        return new PermissionException(null, permission, methodName,
                "User does not have the required permission (" + permission + ")");
    }

//    public static PermissionException createDocumentTypePermissionRequiredException(final String type, final String permission,
//                                                                               final String methodName) {
//        return new PermissionException(type, permission, methodName,
//                "User does not have the required permission (" + permission + ") for document type: " + type);
//    }

    public static PermissionException createDocumentPermissionRequiredException(final Document document, final String permission,
                                                                                final String methodName) {
        return new PermissionException(document.getType(), permission, methodName,
                "User does not have the required permission (" + permission + ") on document (type=" + document.getType() + ", uuid=" + document.getUuid() + ")");
    }
}

@@ -1092,32 +1092,51 @@
 ing methodName,%0A
+                   
             fina
@@ -1147,32 +1147,32 @@
 ring message) %7B%0A
-
         super(me
@@ -1538,24 +1538,79 @@
 tring name,%0A
+                                                       
             
@@ -1628,32 +1628,32 @@
 g methodName) %7B%0A
-
         return n
@@ -2115,439 +2115,8 @@
  %7D%0A%0A
-//    public static PermissionException createDocumentTypePermissionRequiredException(final String type, final String permission,%0A//                                                                               final String methodName) %7B%0A//        return new PermissionException(type, permission, methodName,%0A//                %22User does not have the required permission (%22 + permission + %22) for document type: %22 + type);%0A//    %7D%0A%0A
     

Tidy up.