Author: jbernhardt
Date: Tue Jan 29 13:21:10 2013
New Revision: 1439885

URL: http://svn.apache.org/viewvc?rev=1439885&view=rev
Log:
[SYNCOPE-231]
* Fixing LoggerService
* Code Cleanup


Modified:
    
syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java

Modified: 
syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java?rev=1439885&r1=1439884&r2=1439885&view=diff
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java
 (original)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java
 Tue Jan 29 13:21:10 2013
@@ -39,67 +39,68 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Provider
-public class RestClientExceptionMapper implements ExceptionMapper<Exception>,
-               ResponseExceptionMapper<Exception> {
+public class RestClientExceptionMapper implements ExceptionMapper<Exception>, 
ResponseExceptionMapper<Exception> {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(RestClientExceptionMapper.class);
 
     @Override
-       public Response toResponse(Exception e) {
-               throw new UnsupportedOperationException("Call of toResponse() 
method is not expected in RestClientExceptionnMapper");
-       }
-
-       @Override
-       public Exception fromResponse(Response response) {
-               Exception ex = null;
-               int statusCode = response.getStatus();
-               
-               // 1. Check for composite exception in HTTP header 
-               SyncopeClientCompositeErrorException scce = 
checkCompositeException(response);
-               if (scce != null) {
-                       ex = scce;
-                       
-                       // TODO reduce SCCEE to really composite ones and use 
normal exception for others
-//             } else if (statusCode == HttpStatus.SC_FORBIDDEN) {
-//                     ex = new UnauthorizedRoleException(-1L);
-                       
-                       // 2. Map  SC_UNAUTHORIZED
-               } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
-                       ex = new AccessControlException("Remote unauthorized 
exception");
-                       
-            // 3. Map  SC_BAD_REQUEST
+    public Response toResponse(final Exception e) {
+        throw new UnsupportedOperationException(
+                "Call of toResponse() method is not expected in 
RestClientExceptionnMapper");
+    }
+
+    @Override
+    public Exception fromResponse(final Response response) {
+        Exception ex = null;
+        int statusCode = response.getStatus();
+
+        // 1. Check for composite exception in HTTP header
+        SyncopeClientCompositeErrorException scce = 
checkCompositeException(response);
+        if (scce != null) {
+            ex = scce;
+
+            // TODO reduce SCCEE to really composite ones and use normal 
exception for others
+            // } else if (statusCode == HttpStatus.SC_FORBIDDEN) {
+            // ex = new UnauthorizedRoleException(-1L);
+
+            // 2. Map SC_UNAUTHORIZED
+        } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
+            ex = new AccessControlException("Remote unauthorized exception");
+
+            // 3. Map SC_BAD_REQUEST
         } else if (statusCode == HttpStatus.SC_BAD_REQUEST) {
             ex = new BadRequestException();
 
         } else {
-                       // 4. All other codes are mapped to runtime exception 
with HTTP code information 
-                       ex = new RuntimeException(String.format(
-                                       "Remote exception with status code: %s",
-                                       
Response.Status.fromStatusCode(statusCode).name()));
-               }
+            // 4. All other codes are mapped to runtime exception with HTTP 
code information
+            ex = new RuntimeException(String.format("Remote exception with 
status code: %s", Response.Status
+                    .fromStatusCode(statusCode).name()));
+        }
         LOG.error("Exception thrown by REST methods: " + ex.getMessage(), ex);
-               return ex;
-       }
-       
-       private SyncopeClientCompositeErrorException 
checkCompositeException(Response response) {
-               int statusCode = response.getStatus();
-        List<Object> exceptionTypesInHeaders = 
response.getHeaders().get(SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER);
+        return ex;
+    }
+
+    private SyncopeClientCompositeErrorException checkCompositeException(final 
Response response) {
+        int statusCode = response.getStatus();
+        List<Object> exceptionTypesInHeaders = response.getHeaders().get(
+                SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER);
         if (exceptionTypesInHeaders == null) {
             LOG.debug("No " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER 
+ " provided");
             return null;
         }
 
-               SyncopeClientCompositeErrorException compositeException = new 
SyncopeClientCompositeErrorException(
-                               
org.springframework.http.HttpStatus.valueOf(statusCode));
+        SyncopeClientCompositeErrorException compositeException = new 
SyncopeClientCompositeErrorException(
+                org.springframework.http.HttpStatus.valueOf(statusCode));
 
         Set<String> handledExceptions = new HashSet<String>();
         for (Object exceptionTypeValue : exceptionTypesInHeaders) {
-               String exceptionTypeAsString = (String) exceptionTypeValue; 
+            String exceptionTypeAsString = (String) exceptionTypeValue;
             SyncopeClientExceptionType exceptionType = null;
             try {
                 exceptionType = 
SyncopeClientExceptionType.getFromHeaderValue(exceptionTypeAsString);
             } catch (IllegalArgumentException e) {
-                LOG.error("Unexpected value of " + 
SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + ": " + exceptionTypeAsString, 
e);
+                LOG.error("Unexpected value of " + 
SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + ": "
+                        + exceptionTypeAsString, e);
             }
             if (exceptionType != null) {
                 handledExceptions.add(exceptionTypeAsString);
@@ -108,14 +109,14 @@ public class RestClientExceptionMapper i
                 clientException.setType(exceptionType);
                 if 
(response.getHeaders().get(exceptionType.getElementHeaderName()) != null
                         && 
!response.getHeaders().get(exceptionType.getElementHeaderName()).isEmpty()) {
-                       // TODO: update clientException to support list of 
objects
-                       List<Object> elementsObjectList = 
response.getHeaders().get(exceptionType.getElementHeaderName());
-                       List<String> elementsStringList = new 
ArrayList<String>();
-                       for (Object elementObject : elementsObjectList) {
-                               if (elementObject instanceof String) {
-                                       elementsStringList.add((String) 
elementObject);
-                               }
-                       }
+                    // TODO update clientException to support list of objects
+                    List<Object> elementsObjectList = 
response.getHeaders().get(exceptionType.getElementHeaderName());
+                    List<String> elementsStringList = new ArrayList<String>();
+                    for (Object elementObject : elementsObjectList) {
+                        if (elementObject instanceof String) {
+                            elementsStringList.add((String) elementObject);
+                        }
+                    }
                     clientException.setElements(elementsStringList);
                 }
                 compositeException.addException(clientException);
@@ -130,7 +131,7 @@ public class RestClientExceptionMapper i
         if (compositeException.hasExceptions()) {
             return compositeException;
         }
-        
+
         return null;
-       }
+    }
 }

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java?rev=1439885&r1=1439884&r2=1439885&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java
 Tue Jan 29 13:21:10 2013
@@ -90,12 +90,14 @@ public class LoggerServiceImpl implement
             case NORMAL:
                 loggerController.deleteLog(name);
                 break;
+
             case AUDIT:
                 try {
                     
loggerController.disableAudit(AuditLoggerName.fromLoggerName(name));
                 } catch (Exception e) {
                     throw new BadRequestException(e);
                 }
+                break;
 
             default:
                 throw new BadRequestException();

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java?rev=1439885&r1=1439884&r2=1439885&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
 Tue Jan 29 13:21:10 2013
@@ -35,7 +35,7 @@ import org.springframework.stereotype.Se
 public class UserRequestServiceImpl implements UserRequestService, 
ContextAware {
 
     @Autowired
-    UserRequestController userRequestController;
+    private UserRequestController userRequestController;
 
     private UriInfo uriInfo;
 


Reply via email to