View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.types;
20  
21  import javax.ws.rs.core.Response;
22  
23  public enum ClientExceptionType {
24  
25      AssociatedResources(Response.Status.BAD_REQUEST),
26      Composite(Response.Status.BAD_REQUEST),
27      ConcurrentModification(Response.Status.PRECONDITION_FAILED),
28      ConnectorException(Response.Status.BAD_REQUEST),
29      DataIntegrityViolation(Response.Status.CONFLICT),
30      EntityExists(Response.Status.CONFLICT),
31      GenericPersistence(Response.Status.BAD_REQUEST),
32      InvalidAccessToken(Response.Status.INTERNAL_SERVER_ERROR),
33      InvalidPrivilege(Response.Status.BAD_REQUEST),
34      InvalidImplementation(Response.Status.BAD_REQUEST),
35      InvalidImplementationType(Response.Status.NOT_FOUND),
36      InvalidSecurityAnswer(Response.Status.BAD_REQUEST),
37      InvalidEntity(Response.Status.BAD_REQUEST),
38      InvalidLogger(Response.Status.BAD_REQUEST),
39      InvalidConnInstance(Response.Status.BAD_REQUEST),
40      InvalidConnIdConf(Response.Status.BAD_REQUEST),
41      InvalidPolicy(Response.Status.BAD_REQUEST),
42      InvalidConf(Response.Status.BAD_REQUEST),
43      InvalidPath(Response.Status.BAD_REQUEST),
44      InvalidProvision(Response.Status.BAD_REQUEST),
45      InvalidOrgUnit(Response.Status.BAD_REQUEST),
46      InvalidReport(Response.Status.BAD_REQUEST),
47      InvalidReportExec(Response.Status.BAD_REQUEST),
48      InvalidRelationship(Response.Status.BAD_REQUEST),
49      InvalidRelationshipType(Response.Status.BAD_REQUEST),
50      InvalidAnyType(Response.Status.BAD_REQUEST),
51      InvalidAnyObject(Response.Status.BAD_REQUEST),
52      InvalidGroup(Response.Status.BAD_REQUEST),
53      InvalidSchemaDefinition(Response.Status.BAD_REQUEST),
54      InvalidSearchParameters(Response.Status.BAD_REQUEST),
55      InvalidPageOrSize(Response.Status.BAD_REQUEST),
56      InvalidPropagationTaskExecReport(Response.Status.BAD_REQUEST),
57      InvalidPlainSchema(Response.Status.BAD_REQUEST),
58      InvalidDerSchema(Response.Status.BAD_REQUEST),
59      InvalidVirSchema(Response.Status.BAD_REQUEST),
60      InvalidMapping(Response.Status.BAD_REQUEST),
61      InvalidMembership(Response.Status.BAD_REQUEST),
62      InvalidRealm(Response.Status.BAD_REQUEST),
63      InvalidDynRealm(Response.Status.BAD_REQUEST),
64      InvalidRole(Response.Status.BAD_REQUEST),
65      InvalidUser(Response.Status.BAD_REQUEST),
66      InvalidExternalResource(Response.Status.BAD_REQUEST),
67      InvalidPullTask(Response.Status.BAD_REQUEST),
68      InvalidRequest(Response.Status.BAD_REQUEST),
69      InvalidValues(Response.Status.BAD_REQUEST),
70      NotFound(Response.Status.NOT_FOUND),
71      RealmContains(Response.Status.BAD_REQUEST),
72      RequiredValuesMissing(Response.Status.BAD_REQUEST),
73      RESTValidation(Response.Status.BAD_REQUEST),
74      GroupOwnership(Response.Status.BAD_REQUEST),
75      InUse(Response.Status.BAD_REQUEST),
76      Scheduling(Response.Status.BAD_REQUEST),
77      DelegatedAdministration(Response.Status.FORBIDDEN),
78      Reconciliation(Response.Status.BAD_REQUEST),
79      RunError(Response.Status.INTERNAL_SERVER_ERROR),
80      Unknown(Response.Status.BAD_REQUEST),
81      Workflow(Response.Status.BAD_REQUEST);
82  
83      private final Response.Status responseStatus;
84  
85      ClientExceptionType(final Response.Status responseStatus) {
86          this.responseStatus = responseStatus;
87      }
88  
89      public static ClientExceptionType fromHeaderValue(final String exceptionTypeHeaderValue) {
90          ClientExceptionType result = null;
91          for (ClientExceptionType type : values()) {
92              if (exceptionTypeHeaderValue.equals(type.name())) {
93                  result = type;
94              }
95          }
96  
97          if (result == null) {
98              throw new IllegalArgumentException("Unexpected header value: " + exceptionTypeHeaderValue);
99          }
100 
101         return result;
102     }
103 
104     public String getInfoHeaderValue(final String value) {
105         // HTTP header values cannot contain CR / LF
106         return (name() + ':' + value).replaceAll("(\\r|\\n)", " ");
107     }
108 
109     public Response.Status getResponseStatus() {
110         return responseStatus;
111     }
112 
113 }