EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.rimuhosting.miro.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ParseRimuHostingException.java]

nameclass, %method, %block, %line, %
ParseRimuHostingException.java50%  (1/2)33%  (1/3)9%   (6/70)20%  (3/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseRimuHostingException$10%   (0/1)0%   (0/1)0%   (0/6)0%   (0/1)
ParseRimuHostingException$1 (ParseRimuHostingException): void 0%   (0/1)0%   (0/6)0%   (0/1)
     
class ParseRimuHostingException100% (1/1)50%  (1/2)9%   (6/64)20%  (3/15)
apply (Exception): Object 0%   (0/1)0%   (0/58)0%   (0/12)
ParseRimuHostingException (Json): void 100% (1/1)100% (6/6)100% (3/3)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds 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 */
19package org.jclouds.rimuhosting.miro.functions;
20 
21import static org.jclouds.util.Throwables2.propagateOrNull;
22 
23import java.lang.reflect.Type;
24import java.util.Map;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.http.HttpResponseException;
30import org.jclouds.json.Json;
31import org.jclouds.rest.AuthorizationException;
32import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
33 
34import com.google.common.base.Function;
35import com.google.common.collect.Iterables;
36import com.google.gson.reflect.TypeToken;
37 
38/**
39 * On non 2xx we have an error. RimuHosting using the same json base object.
40 * 
41 * TODO: map exceptions out into something that suits jclouds.
42 * 
43 * @author Ivan Meredith
44 */
45@Singleton
46public class ParseRimuHostingException implements Function<Exception, Object> {
47   private Json json;
48 
49   @Inject
50   public ParseRimuHostingException(Json json) {
51      this.json = json;
52   }
53 
54   @Override
55   public Object apply(Exception e) {
56      if (e instanceof HttpResponseException) {
57         HttpResponseException responseException = (HttpResponseException) e;
58         if (responseException.getContent() != null) {
59            Type setType = new TypeToken<Map<String, RimuHostingResponse>>() {
60            }.getType();
61            String test = responseException.getContent();
62            Map<String, RimuHostingResponse> responseMap = json.fromJson(test, setType);
63            RimuHostingResponse firstResponse = Iterables.get(responseMap.values(), 0);
64            String errorClass = firstResponse.getErrorInfo().getErrorClass();
65            if (errorClass.equals("PermissionException"))
66               throw new AuthorizationException(
67                        firstResponse.getErrorInfo().getErrorMessage(), responseException);
68            throw new RuntimeException(firstResponse.getErrorInfo().getErrorMessage(), e);
69         }
70      }
71      return propagateOrNull(e);
72   }
73}

[all classes][org.jclouds.rimuhosting.miro.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov