Changeset 1862


Ignore:
Timestamp:
04/05/12 14:52:00 (12 years ago)
Author:
twagoo
Message:

Fixed NPE because of eager log message

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1860 r1862  
    5252@Path("/registry")
    5353public class ComponentRegistryRestService {
    54    
     54
    5555    @Context
    5656    private UriInfo uriInfo;
     
    6969    @Inject(value = "componentRegistryFactory")
    7070    private ComponentRegistryFactory componentRegistryFactory;
    71    
     71
    7272    private ComponentRegistry getRegistry(boolean userspace) {
    7373        Principal userPrincipal = security.getUserPrincipal();
     
    7575        return getRegistry(userspace, userCredentials);
    7676    }
    77    
     77
    7878    private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) {
    7979        return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
     
    9292        return principal;
    9393    }
    94    
     94
    9595    private UserCredentials getUserCredentials(Principal userPrincipal) {
    9696        UserCredentials userCredentials = null;
     
    100100        return userCredentials;
    101101    }
    102    
     102
    103103    @GET
    104104    @Path("/components")
     
    111111        return components;
    112112    }
    113    
     113
    114114    @GET
    115115    @Path("/profiles")
     
    118118            @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException {
    119119        long start = System.currentTimeMillis();
    120        
     120
    121121        List<ProfileDescription> profiles;
    122122        if (metadataEditor) {
     
    125125            profiles = getRegistry(userspace).getProfileDescriptions();
    126126        }
    127        
     127
    128128        LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
    129129                + " millisecs)");
    130130        return profiles;
    131131    }
    132    
     132
    133133    @GET
    134134    @Path("/components/{componentId}")
     
    139139        return getRegistry(userspace).getMDComponent(componentId);
    140140    }
    141    
     141
    142142    @GET
    143143    @Path("/components/{componentId}/{rawType}")
     
    156156            if ("xml".equalsIgnoreCase(rawType)) {
    157157                result = new StreamingOutput() {
    158                    
     158
    159159                    @Override
    160160                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    169169            } else if ("xsd".equalsIgnoreCase(rawType)) {
    170170                result = new StreamingOutput() {
    171                    
     171
    172172                    @Override
    173173                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    178178                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    179179                        }
    180                        
     180
    181181                    }
    182182                };
     
    191191        }
    192192    }
    193    
     193
    194194    public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException {
    195195        AbstractDescription desc = null;
     
    208208        return result;
    209209    }
    210    
     210
    211211    @GET
    212212    @Path("/profiles/{profileId}")
     
    217217        return getRegistry(userspace).getMDProfile(profileId);
    218218    }
    219    
     219
    220220    @GET
    221221    @Path("/components/usage/{componentId}")
     
    227227            List<ComponentDescription> components = registry.getUsageInComponents(componentId);
    228228            List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId);
    229            
     229
    230230            LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId
    231231                    + " (" + (System.currentTimeMillis() - start) + " millisecs)");
    232            
     232
    233233            List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size());
    234234            usages.addAll(components);
    235235            usages.addAll(profiles);
    236            
     236
    237237            return usages;
    238238        } catch (ComponentRegistryException e) {
     
    241241        }
    242242    }
    243    
     243
    244244    @GET
    245245    @Path("/profiles/{profileId}/comments")
     
    252252        return comments;
    253253    }
    254    
     254
    255255    @GET
    256256    @Path("/components/{componentId}/comments")
     
    263263        return comments;
    264264    }
    265    
     265
    266266    @GET
    267267    @Path("/profiles/{profileId}/comments/{commentId}")
     
    271271        return getRegistry(userspace).getSpecifiedCommentInProfile(profileId, commentId);
    272272    }
    273    
     273
    274274    @GET
    275275    @Path("/components/{componentId}/comments/{commentId}")
     
    299299        }
    300300    }
    301    
     301
    302302    @POST
    303303    @Path("/profiles/{profileId}/comments/{commentId}")
     
    310310        }
    311311    }
    312    
     312
    313313    @POST
    314314    @Path("/components/{componentId}/comments/{commentId}")
     
    321321        }
    322322    }
    323    
     323
    324324    @POST
    325325    @Path("/profiles/{profileId}/publish")
     
    345345        }
    346346    }
    347    
     347
    348348    @POST
    349349    @Path("/profiles/{profileId}/update")
     
    370370            return Response.status(Status.UNAUTHORIZED).entity(ex.getMessage()).build();
    371371        }
    372        
     372
    373373    }
    374374
     
    392392        }
    393393    }
    394    
     394
    395395    @POST
    396396    @Path("/components/{componentId}/publish")
     
    417417        }
    418418    }
    419    
     419
    420420    @POST
    421421    @Path("/components/{componentId}/update")
     
    442442        }
    443443    }
    444    
     444
    445445    private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) {
    446446        desc.setName(name);
     
    450450        desc.setRegistrationDate(AbstractDescription.createNewDate());
    451451    }
    452    
     452
    453453    @DELETE
    454454    @Path("/components/{componentId}")
     
    476476        return Response.ok().build();
    477477    }
    478    
     478
    479479    @DELETE
    480480    @Path("/profiles/{profileId}")
     
    501501        return Response.ok().build();
    502502    }
    503    
     503
    504504    @DELETE
    505505    @Path("/profiles/{profileId}/comments/{commentId}")
     
    532532        return Response.ok().build();
    533533    }
    534    
     534
    535535    @DELETE
    536536    @Path("/components/{componentId}/comments/{commentId}")
     
    563563        return Response.ok().build();
    564564    }
    565    
     565
    566566    @GET
    567567    @Path("/profiles/{profileId}/{rawType}")
     
    578578            checkAndThrowDescription(desc, profileId);
    579579            String fileName = desc.getName() + "." + rawType;
    580            
     580
    581581            if ("xml".equalsIgnoreCase(rawType)) {
    582582                result = new StreamingOutput() {
    583                    
     583
    584584                    @Override
    585585                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    594594            } else if ("xsd".equalsIgnoreCase(rawType)) {
    595595                result = new StreamingOutput() {
    596                    
     596
    597597                    @Override
    598598                    public void write(OutputStream output) throws IOException, WebApplicationException {
     
    615615        }
    616616    }
    617    
     617
    618618    private void checkAndThrowDescription(AbstractDescription desc, String id) {
    619619        if (desc == null) {
     
    621621        }
    622622    }
    623    
     623
    624624    private Response createDownloadResponse(StreamingOutput result, String fileName) {
    625625        //Making response so it triggers browsers native save as dialog.
     
    627627                "attachment; filename=\"" + fileName + "\"").entity(result).build();
    628628        return response;
    629        
    630     }
    631    
     629
     630    }
     631
    632632    @POST
    633633    @Path("/profiles")
     
    653653        }
    654654    }
    655    
     655
    656656    @POST
    657657    @Path("/components")
     
    677677        }
    678678    }
    679    
     679
    680680    @POST
    681681    @Path("/components/{componentId}/comments")
     
    703703        }
    704704    }
    705    
     705
    706706    @POST
    707707    @Path("/profiles/{profileId}/comments")
     
    729729        }
    730730    }
    731    
     731
    732732    @GET
    733733    @Path("/pingSession")
     
    744744        return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
    745745    }
    746    
     746
    747747    private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace,
    748748            RegisterAction action) {
     
    779779            }
    780780            response.setIsProfile(desc.isProfile());
    781             LOG.info("Registration of {} successful: {}", response.getDescription().getId(), response.isRegistered());
     781            if (response.isRegistered()) {
     782                LOG.info("Registration of {} was successful", response.getDescription().getId());
     783            }
    782784            return Response.ok(response).build();
    783785        } finally {
     
    789791        }
    790792    }
    791    
     793
    792794    private Response registerComment(InputStream input, ComponentRegistry registry, boolean userspace,
    793795            AbstractDescription description, Principal principal, UserCredentials userCredentials) {
     
    809811                    }
    810812                }
    811                
     813
    812814                int returnCode = registry.registerComment(com, principal.getName());
    813815                if (returnCode == 0) {
     
    835837        }
    836838    }
    837    
     839
    838840    private ComponentDescription createNewComponentDescription() {
    839841        ComponentDescription desc = ComponentDescription.createNewDescription();
     
    841843        return desc;
    842844    }
    843    
     845
    844846    private ProfileDescription createNewProfileDescription() {
    845847        ProfileDescription desc = ProfileDescription.createNewDescription();
     
    847849        return desc;
    848850    }
    849    
     851
    850852    private Comment createNewComment() {
    851853        Comment com = Comment.createANewComment();
    852854        return com;
    853855    }
    854    
     856
    855857    private String createXlink(String id) {
    856858        URI uri = uriInfo.getRequestUriBuilder().path(id).build();
    857859        return uri.toString();
    858860    }
    859    
     861
    860862    private void validate(RegisterResponse response, Validator... validators) {
    861863        for (Validator validator : validators) {
     
    867869        }
    868870    }
    869    
     871
    870872    private void validateComment(CommentResponse response, Validator... validators) {
    871873        for (Validator validator : validators) {
Note: See TracChangeset for help on using the changeset viewer.