Ignore:
Timestamp:
11/28/11 15:46:02 (13 years ago)
Author:
jeafer
Message:

Jean-Charles branch initial commit,
Changes regarding comment on the ComponentRegistry service.
Get comment from RestService? to Database access (CommentsDao?) implemented.
TestComment? class in development

Location:
ComponentRegistry/branches/jeaferversion
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry

    • Property svn:ignore
      •  

        old new  
        77profiles.xml
        88nb-configuration.xml
         9nbactions-Run without tests.xml
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1604 r1631  
    4141import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    4242import clarin.cmdi.componentregistry.model.AbstractDescription;
     43import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
    4344import clarin.cmdi.componentregistry.model.ComponentDescription;
    4445import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    6970
    7071    private ComponentRegistry getRegistry(boolean userspace) {
    71         Principal userPrincipal = security.getUserPrincipal();
    72         UserCredentials userCredentials = getUserCredentials(userPrincipal);
    73         return getRegistry(userspace, userCredentials);
     72        Principal userPrincipal = security.getUserPrincipal();
     73        UserCredentials userCredentials = getUserCredentials(userPrincipal);
     74        return getRegistry(userspace, userCredentials);
    7475    }
    7576
    7677    private ComponentRegistry getRegistry(boolean userspace, UserCredentials userCredentials) {
    77         return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
     78        return componentRegistryFactory.getComponentRegistry(userspace, userCredentials);
    7879    }
    7980
    8081    private Principal checkAndGetUserPrincipal() {
    81         Principal principal = security.getUserPrincipal();
    82         if (principal == null) {
    83             throw new IllegalArgumentException("no user principal found.");
    84         }
    85         return principal;
     82        Principal principal = security.getUserPrincipal();
     83        if (principal == null) {
     84            throw new IllegalArgumentException("no user principal found.");
     85        }
     86        return principal;
    8687    }
    8788
    8889    private UserCredentials getUserCredentials(Principal userPrincipal) {
    89         UserCredentials userCredentials = null;
    90         if (userPrincipal != null) {
    91             userCredentials = new UserCredentials(userPrincipal);
    92         }
    93         return userCredentials;
     90        UserCredentials userCredentials = null;
     91        if (userPrincipal != null) {
     92            userCredentials = new UserCredentials(userPrincipal);
     93        }
     94        return userCredentials;
    9495    }
    9596
     
    9899    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    99100    public List<ComponentDescription> getRegisteredComponents(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    100         long start = System.currentTimeMillis();
    101         List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
    102         LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
    103                 + " millisecs)");
    104         return components;
     101        long start = System.currentTimeMillis();
     102        List<ComponentDescription> components = getRegistry(userspace).getComponentDescriptions();
     103        LOG.info("Releasing " + components.size() + " registered components into the world (" + (System.currentTimeMillis() - start)
     104                + " millisecs)");
     105        return components;
    105106    }
    106107
     
    109110    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    110111    public List<ProfileDescription> getRegisteredProfiles(@QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace,
    111             @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException {
    112         long start = System.currentTimeMillis();
    113        
    114         List<ProfileDescription> profiles;
    115         if (metadataEditor) {
    116             profiles = getRegistry(userspace).getProfileDescriptionsForMetadaEditor();
    117         } else {
    118             profiles = getRegistry(userspace).getProfileDescriptions();
    119         }
    120        
    121         LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
    122                 + " millisecs)");
    123         return profiles;
     112            @QueryParam(METADATA_EDITOR_PARAM) @DefaultValue("false") boolean metadataEditor) throws ComponentRegistryException {
     113        long start = System.currentTimeMillis();
     114
     115        List<ProfileDescription> profiles;
     116        if (metadataEditor) {
     117            profiles = getRegistry(userspace).getProfileDescriptionsForMetadaEditor();
     118        } else {
     119            profiles = getRegistry(userspace).getProfileDescriptions();
     120        }
     121
     122        LOG.info("Releasing " + profiles.size() + " registered profiles into the world (" + (System.currentTimeMillis() - start)
     123                + " millisecs)");
     124        return profiles;
    124125    }
    125126
     
    128129    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    129130    public CMDComponentSpec getRegisteredComponent(@PathParam("componentId") String componentId,
    130             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    131         LOG.info("Component with id: " + componentId + " is requested.");
    132         return getRegistry(userspace).getMDComponent(componentId);
     131            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     132        LOG.info("Component with id: " + componentId + " is requested.");
     133        return getRegistry(userspace).getMDComponent(componentId);
    133134    }
    134135
     
    137138    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
    138139    public Response getRegisteredComponentRawType(@PathParam("componentId") final String componentId, @PathParam("rawType") String rawType) {
    139         LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested.");
    140         StreamingOutput result = null;
    141         try {
    142             final ComponentRegistry registry = findRegistry(componentId, new ComponentClosure());
    143             if (registry == null) {
    144                 return Response.status(Status.NOT_FOUND).entity("Id: " + componentId + " is not registered, cannot create data.").build();
    145             }
    146             ComponentDescription desc = registry.getComponentDescription(componentId);
    147             checkAndThrowDescription(desc, componentId);
    148             String fileName = desc.getName() + "." + rawType;
    149             if ("xml".equalsIgnoreCase(rawType)) {
    150                 result = new StreamingOutput() {
    151 
    152                     @Override
    153                     public void write(OutputStream output) throws IOException, WebApplicationException {
    154                         try {
    155                             registry.getMDComponentAsXml(componentId, output);
    156                         } catch (ComponentRegistryException e) {
    157                             LOG.info("Could not retrieve component", e);
    158                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    159                         }
    160                     }
    161                 };
    162             } else if ("xsd".equalsIgnoreCase(rawType)) {
    163                 result = new StreamingOutput() {
    164 
    165                     @Override
    166                     public void write(OutputStream output) throws IOException, WebApplicationException {
    167                         try {
    168                             registry.getMDComponentAsXsd(componentId, output);
    169                         } catch (ComponentRegistryException e) {
    170                             LOG.info("Could not retrieve component", e);
    171                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    172                         }
    173 
    174                     }
    175                 };
    176             } else {
    177                 throw new WebApplicationException(Response.serverError().entity(
    178                         "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
    179             }
    180             return createDownloadResponse(result, fileName);
    181         } catch (ComponentRegistryException e) {
    182             LOG.info("Could not retrieve component", e);
    183             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    184         }
     140        LOG.info("Component with id: " + componentId + " and rawType:" + rawType + " is requested.");
     141        StreamingOutput result = null;
     142        try {
     143            final ComponentRegistry registry = findRegistry(componentId, new ComponentClosure());
     144            if (registry == null) {
     145                return Response.status(Status.NOT_FOUND).entity("Id: " + componentId + " is not registered, cannot create data.").build();
     146            }
     147            ComponentDescription desc = registry.getComponentDescription(componentId);
     148            checkAndThrowDescription(desc, componentId);
     149            String fileName = desc.getName() + "." + rawType;
     150            if ("xml".equalsIgnoreCase(rawType)) {
     151                result = new StreamingOutput() {
     152
     153                    @Override
     154                    public void write(OutputStream output) throws IOException, WebApplicationException {
     155                        try {
     156                            registry.getMDComponentAsXml(componentId, output);
     157                        } catch (ComponentRegistryException e) {
     158                            LOG.info("Could not retrieve component", e);
     159                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     160                        }
     161                    }
     162                };
     163            } else if ("xsd".equalsIgnoreCase(rawType)) {
     164                result = new StreamingOutput() {
     165
     166                    @Override
     167                    public void write(OutputStream output) throws IOException, WebApplicationException {
     168                        try {
     169                            registry.getMDComponentAsXsd(componentId, output);
     170                        } catch (ComponentRegistryException e) {
     171                            LOG.info("Could not retrieve component", e);
     172                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     173                        }
     174
     175                    }
     176                };
     177            } else {
     178                throw new WebApplicationException(Response.serverError().entity(
     179                        "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
     180            }
     181            return createDownloadResponse(result, fileName);
     182        } catch (ComponentRegistryException e) {
     183            LOG.info("Could not retrieve component", e);
     184            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     185        }
    185186    }
    186187
    187188    public ComponentRegistry findRegistry(String id, RegistryClosure<? extends AbstractDescription> clos) throws ComponentRegistryException {
    188         AbstractDescription desc = null;
    189         ComponentRegistry result = getRegistry(false);
    190         desc = clos.getDescription(result, id);
    191         if (desc == null) {
    192             List<ComponentRegistry> userRegs = componentRegistryFactory.getAllUserRegistries();
    193             for (ComponentRegistry reg : userRegs) {
    194                 desc = clos.getDescription(reg, id);
    195                 if (desc != null) {
    196                     result = reg;
    197                     break;
    198                 }
    199             }
    200         }
    201         return result;
     189        AbstractDescription desc = null;
     190        ComponentRegistry result = getRegistry(false);
     191        desc = clos.getDescription(result, id);
     192        if (desc == null) {
     193            List<ComponentRegistry> userRegs = componentRegistryFactory.getAllUserRegistries();
     194            for (ComponentRegistry reg : userRegs) {
     195                desc = clos.getDescription(reg, id);
     196                if (desc != null) {
     197                    result = reg;
     198                    break;
     199                }
     200            }
     201        }
     202        return result;
    202203    }
    203204
     
    206207    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    207208    public CMDComponentSpec getRegisteredProfile(@PathParam("profileId") String profileId,
    208             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    209         LOG.info("Profile with id: " + profileId + " is requested.");
    210         return getRegistry(userspace).getMDProfile(profileId);
     209            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     210        LOG.info("Profile with id: " + profileId + " is requested.");
     211        return getRegistry(userspace).getMDProfile(profileId);
    211212    }
    212213
     
    215216    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    216217    public List<AbstractDescription> getComponentUsage(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("true") boolean userspace) throws ComponentRegistryException {
    217         try {
    218             final long start = System.currentTimeMillis();
    219             ComponentRegistry registry = getRegistry(userspace);
    220             List<ComponentDescription> components = registry.getUsageInComponents(componentId);
    221             List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId);
    222 
    223             LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId
    224                     + " (" + (System.currentTimeMillis() - start) + " millisecs)");
    225 
    226             List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size());
    227             usages.addAll(components);
    228             usages.addAll(profiles);
    229 
    230             return usages;
    231         } catch (ComponentRegistryException e) {
    232             LOG.info("Could not retrieve profile usage", e);
    233             throw e;
    234         }
     218        try {
     219            final long start = System.currentTimeMillis();
     220            ComponentRegistry registry = getRegistry(userspace);
     221            List<ComponentDescription> components = registry.getUsageInComponents(componentId);
     222            List<ProfileDescription> profiles = registry.getUsageInProfiles(componentId);
     223
     224            LOG.info("Found " + components.size() + " components and " + profiles.size() + " profiles that use component " + componentId
     225                    + " (" + (System.currentTimeMillis() - start) + " millisecs)");
     226
     227            List<AbstractDescription> usages = new ArrayList<AbstractDescription>(components.size() + profiles.size());
     228            usages.addAll(components);
     229            usages.addAll(profiles);
     230
     231            return usages;
     232        } catch (ComponentRegistryException e) {
     233            LOG.info("Could not retrieve profile usage", e);
     234            throw e;
     235        }
     236    }
     237
     238    @GET
     239    @Path("/profile/{profileId}/comments")
     240    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     241    public List<Comment> getRegisteredCommentsFromProfile(@PathParam("profileId") String profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     242        long start = System.currentTimeMillis();
     243        List<Comment> comments = getRegistry(userspace).getCommentsInProfile(profileId);
     244        LOG.info("Releasing " + comments.size() + " registered comments in Profile into the world (" + (System.currentTimeMillis() - start)
     245                + " millisecs)");
     246        return comments;
     247    }
     248
     249    @GET
     250    @Path("/component/{componentId}/comments")
     251    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     252    public List<Comment> getRegisteredCommentsFromComponent(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     253        long start = System.currentTimeMillis();
     254        List<Comment> comments = getRegistry(userspace).getCommentsInComponent(componentId);
     255        LOG.info("Releasing " + comments.size() + " registered comments in Component into the world (" + (System.currentTimeMillis() - start)
     256                + " millisecs)");
     257        return comments;
     258    }
     259
     260    @GET
     261    @Path("/profiles/{profileId}/comments/{commentsId}")
     262    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     263    public Comment getSpecifiedCommentFromProfile(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     264        long start = System.currentTimeMillis();
     265        LOG.info(" Comments of component with id" + commentId + " are requested.");
     266        return getRegistry(userspace).getSpecifiedCommentInProfile(commentId);
     267    }
     268
     269    @GET
     270    @Path("/component/{componentId}/comments/{commentsId}")
     271    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     272    public Comment getRegisteredCommentFromComponent(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     273        LOG.info(" Comments of component with id" + commentId + " are requested.");
     274        return getRegistry(userspace).getSpecifiedCommentInComponent(commentId);
    235275    }
    236276
     
    246286    @Path("/profiles/{profileId}")
    247287    public Response manipulateRegisteredProfile(@PathParam("profileId") String profileId, @FormParam("method") String method,
    248             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    249         if ("delete".equalsIgnoreCase(method)) {
    250             return deleteRegisteredProfile(profileId, userspace);
    251         } else {
    252             return Response.ok().build();
    253         }
    254     }
     288            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     289        if ("delete".equalsIgnoreCase(method)) {
     290            return deleteRegisteredProfile(profileId, userspace);
     291        } else {
     292            return Response.ok().build();
     293        }
     294    }
     295
     296//    @POST
     297//    @Path("/profiles/{profileId}/comments/{commentId}")
     298//    public Response manipulateRegisteredCommentFromProfile(@PathParam("profileId") String commentId, @FormParam("method") String method,
     299//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     300//        if ("delete".equalsIgnoreCase(method)) {
     301//            return deleteRegisteredProfile(commentId, userspace);
     302//        } else {
     303//            return Response.ok().build();
     304//        }
     305//    }
     306//
     307//    @POST
     308//    @Path("/components/{componentId}/comments/{commentId}")
     309//    public Response manipulateRegisteredCommentFromComponent(@PathParam("profileId") String commentId, @FormParam("method") String method,
     310//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     311//        if ("delete".equalsIgnoreCase(method)) {
     312//            return deleteRegisteredProfile(commentId, userspace);
     313//        } else {
     314//            return Response.ok().build();
     315//        }
     316//    }
    255317
    256318    @POST
     
    258320    @Consumes("multipart/form-data")
    259321    public Response publishRegisteredProfile(@PathParam("profileId") String profileId, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    260             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    261             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    262         Principal principal = checkAndGetUserPrincipal();
    263         try {
    264             ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
    265             if (desc != null) {
    266                 updateDescription(desc, name, description, domainName, group);
    267                 return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
    268             } else {
    269                 LOG.error("Update of nonexistent id (" + profileId + ") failed.");
    270                 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    271             }
    272         } catch (ComponentRegistryException e) {
    273             LOG.info("Could not retrieve component", e);
    274             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    275         }
     322            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     323            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     324        Principal principal = checkAndGetUserPrincipal();
     325        try {
     326            ProfileDescription desc = getRegistry(true).getProfileDescription(profileId);
     327            if (desc != null) {
     328                updateDescription(desc, name, description, domainName, group);
     329                return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
     330            } else {
     331                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     332                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     333            }
     334        } catch (ComponentRegistryException e) {
     335            LOG.info("Could not retrieve component", e);
     336            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     337        }
    276338    }
    277339
     
    280342    @Consumes("multipart/form-data")
    281343    public Response updateRegisteredProfile(@PathParam("profileId") String profileId,
    282             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    283             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    284             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    285         Principal principal = checkAndGetUserPrincipal();
    286         UserCredentials userCredentials = getUserCredentials(principal);
    287         try {
    288             ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
    289             if (desc != null) {
    290                 updateDescription(desc, name, description, domainName, group);
    291                 return register(input, desc, userCredentials, userspace, new UpdateAction(principal));
    292             } else {
    293                 LOG.error("Update of nonexistent id (" + profileId + ") failed.");
    294                 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    295             }
    296         } catch (ComponentRegistryException e) {
    297             LOG.info("Could not retrieve component", e);
    298             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    299         }
     344            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
     345            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     346            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     347        Principal principal = checkAndGetUserPrincipal();
     348        UserCredentials userCredentials = getUserCredentials(principal);
     349        try {
     350            ProfileDescription desc = getRegistry(userspace).getProfileDescription(profileId);
     351            if (desc != null) {
     352                updateDescription(desc, name, description, domainName, group);
     353                return register(input, desc, userCredentials, userspace, new UpdateAction(principal));
     354            } else {
     355                LOG.error("Update of nonexistent id (" + profileId + ") failed.");
     356                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     357            }
     358        } catch (ComponentRegistryException e) {
     359            LOG.info("Could not retrieve component", e);
     360            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     361        }
    300362    }
    301363
     
    311373    @Path("/components/{componentId}")
    312374    public Response manipulateRegisteredComponent(@PathParam("componentId") String componentId, @FormParam("method") String method,
    313             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    314         if ("delete".equalsIgnoreCase(method)) {
    315             return deleteRegisteredComponent(componentId, userspace);
    316         } else {
    317             return Response.ok().build();
    318         }
     375            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     376        if ("delete".equalsIgnoreCase(method)) {
     377            return deleteRegisteredComponent(componentId, userspace);
     378        } else {
     379            return Response.ok().build();
     380        }
    319381    }
    320382
     
    323385    @Consumes("multipart/form-data")
    324386    public Response publishRegisteredComponent(@PathParam("componentId") String componentId,
    325             @FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    326             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
    327             @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    328         Principal principal = checkAndGetUserPrincipal();
    329         try {
    330             ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
    331             if (desc != null) {
    332                 updateDescription(desc, name, description, domainName, group);
    333                 return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
    334             } else {
    335                 LOG.error("Update of nonexistent id (" + componentId + ") failed.");
    336                 return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
    337             }
    338         } catch (ComponentRegistryException e) {
    339             LOG.info("Could not retrieve component", e);
    340             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    341         }
     387            @FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
     388            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
     389            @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     390        Principal principal = checkAndGetUserPrincipal();
     391        try {
     392            ComponentDescription desc = getRegistry(true).getComponentDescription(componentId);
     393            if (desc != null) {
     394                updateDescription(desc, name, description, domainName, group);
     395                return register(input, desc, getUserCredentials(principal), true, new PublishAction(principal));
     396            } else {
     397                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
     398                return Response.serverError().entity("Invalid id, cannot update nonexistent profile").build();
     399            }
     400        } catch (ComponentRegistryException e) {
     401            LOG.info("Could not retrieve component", e);
     402            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     403        }
    342404    }
    343405
     
    346408    @Consumes("multipart/form-data")
    347409    public Response updateRegisteredComponent(@PathParam("componentId") String componentId,
    348             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
    349             @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
    350             @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
    351         Principal principal = checkAndGetUserPrincipal();
    352         try {
    353             ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
    354             if (desc != null) {
    355                 updateDescription(desc, name, description, domainName, group);
    356                 return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction(principal));
    357             } else {
    358                 LOG.error("Update of nonexistent id (" + componentId + ") failed.");
    359                 return Response.serverError().entity("Invalid id, cannot update nonexistent component").build();
    360             }
    361         } catch (ComponentRegistryException e) {
    362             LOG.info("Could not retrieve component", e);
    363             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    364         }
     410            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace, @FormDataParam(DATA_FORM_FIELD) InputStream input,
     411            @FormDataParam(NAME_FORM_FIELD) String name, @FormDataParam(DESCRIPTION_FORM_FIELD) String description,
     412            @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName) {
     413        Principal principal = checkAndGetUserPrincipal();
     414        try {
     415            ComponentDescription desc = getRegistry(userspace).getComponentDescription(componentId);
     416            if (desc != null) {
     417                updateDescription(desc, name, description, domainName, group);
     418                return register(input, desc, getUserCredentials(principal), userspace, new UpdateAction(principal));
     419            } else {
     420                LOG.error("Update of nonexistent id (" + componentId + ") failed.");
     421                return Response.serverError().entity("Invalid id, cannot update nonexistent component").build();
     422            }
     423        } catch (ComponentRegistryException e) {
     424            LOG.info("Could not retrieve component", e);
     425            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     426        }
    365427    }
    366428
    367429    private void updateDescription(AbstractDescription desc, String name, String description, String domainName, String group) {
    368         desc.setName(name);
    369         desc.setDescription(description);
    370         desc.setDomainName(domainName);
    371         desc.setGroupName(group);
    372         desc.setRegistrationDate(AbstractDescription.createNewDate());
     430        desc.setName(name);
     431        desc.setDescription(description);
     432        desc.setDomainName(domainName);
     433        desc.setGroupName(group);
     434        desc.setRegistrationDate(AbstractDescription.createNewDate());
    373435    }
    374436
     
    376438    @Path("/components/{componentId}")
    377439    public Response deleteRegisteredComponent(@PathParam("componentId") String componentId,
    378             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    379         Principal principal = checkAndGetUserPrincipal();
    380         ComponentRegistry registry = getRegistry(userspace);
    381         LOG.info("Component with id: " + componentId + " set for deletion.");
    382         try {
    383             registry.deleteMDComponent(componentId, principal, false);
    384         } catch (DeleteFailedException e) {
    385             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    386             return Response.status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    387         } catch (ComponentRegistryException e) {
    388             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    389             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    390         } catch (IOException e) {
    391             LOG.info("Component with id: " + componentId + " deletion failed.", e);
    392             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    393         } catch (UserUnauthorizedException e) {
    394             LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage());
    395             return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    396         }
    397         LOG.info("Component with id: " + componentId + " deleted.");
    398         return Response.ok().build();
     440            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     441        Principal principal = checkAndGetUserPrincipal();
     442        ComponentRegistry registry = getRegistry(userspace);
     443        LOG.info("Component with id: " + componentId + " set for deletion.");
     444        try {
     445            registry.deleteMDComponent(componentId, principal, false);
     446        } catch (DeleteFailedException e) {
     447            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     448            return Response.status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     449        } catch (ComponentRegistryException e) {
     450            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     451            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     452        } catch (IOException e) {
     453            LOG.info("Component with id: " + componentId + " deletion failed.", e);
     454            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     455        } catch (UserUnauthorizedException e) {
     456            LOG.info("Component with id: " + componentId + " deletion failed: " + e.getMessage());
     457            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     458        }
     459        LOG.info("Component with id: " + componentId + " deleted.");
     460        return Response.ok().build();
    399461    }
    400462
     
    402464    @Path("/profiles/{profileId}")
    403465    public Response deleteRegisteredProfile(@PathParam("profileId") String profileId,
    404             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    405         Principal principal = checkAndGetUserPrincipal();
    406         LOG.info("Profile with id: " + profileId + " set for deletion.");
    407         try {
    408             getRegistry(userspace).deleteMDProfile(profileId, principal);
    409         } catch (DeleteFailedException e) {
    410             LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
    411             return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    412         } catch (ComponentRegistryException e) {
    413             LOG.info("Could not retrieve component", e);
    414             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    415         } catch (IOException e) {
    416             LOG.info("Profile with id: " + profileId + " deletion failed.", e);
    417             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    418         } catch (UserUnauthorizedException e) {
    419             LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
    420             return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    421         }
    422         LOG.info("Profile with id: " + profileId + " deleted.");
    423         return Response.ok().build();
    424     }
     466            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     467        Principal principal = checkAndGetUserPrincipal();
     468        LOG.info("Profile with id: " + profileId + " set for deletion.");
     469        try {
     470            getRegistry(userspace).deleteMDProfile(profileId, principal);
     471        } catch (DeleteFailedException e) {
     472            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     473            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     474        } catch (ComponentRegistryException e) {
     475            LOG.info("Could not retrieve component", e);
     476            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     477        } catch (IOException e) {
     478            LOG.info("Profile with id: " + profileId + " deletion failed.", e);
     479            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     480        } catch (UserUnauthorizedException e) {
     481            LOG.info("Profile with id: " + profileId + " deletion failed: " + e.getMessage());
     482            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     483        }
     484        LOG.info("Profile with id: " + profileId + " deleted.");
     485        return Response.ok().build();
     486    }
     487
     488//    @DELETE
     489//    @Path("/profiles/{profileId}/comments/{commentId}")
     490//    public Response deleteRegisteredCommentFromProfile(@PathParam("commentId") String commentId,
     491//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     492//        Principal principal = checkAndGetUserPrincipal();
     493//        LOG.info("Comment with id: " + commentId + " set for deletion.");
     494//        try {
     495//            getRegistry(userspace).deleteMDComment(commentId, principal);
     496//        } catch (DeleteFailedException e) {
     497//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     498//            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     499//        } catch (ComponentRegistryException e) {
     500//            LOG.info("Could not retrieve component", e);
     501//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     502//        } catch (IOException e) {
     503//            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
     504//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     505//        } catch (UserUnauthorizedException e) {
     506//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     507//            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     508//        }
     509//        LOG.info("Profile with id: " + commentId + " deleted.");
     510//        return Response.ok().build();
     511//    }
     512//
     513//    @DELETE
     514//    @Path("/components/{componentId}/comments/{commentId}")
     515//    public Response deleteRegisteredCommentFromComponent(@PathParam("commentId") String commentId,
     516//            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     517//        Principal principal = checkAndGetUserPrincipal();
     518//        LOG.info("Comment with id: " + commentId + " set for deletion.");
     519//        try {
     520//            getRegistry(userspace).deleteMDComment(commentId, principal);
     521//        } catch (DeleteFailedException e) {
     522//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     523//            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     524//        } catch (ComponentRegistryException e) {
     525//            LOG.info("Could not retrieve component", e);
     526//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     527//        } catch (IOException e) {
     528//            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
     529//            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     530//        } catch (UserUnauthorizedException e) {
     531//            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     532//            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     533//        }
     534//        LOG.info("Profile with id: " + commentId + " deleted.");
     535//        return Response.ok().build();
     536//    }
    425537
    426538    @GET
     
    428540    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
    429541    public Response getRegisteredProfileRawType(@PathParam("profileId") final String profileId, @PathParam("rawType") String rawType) {
    430         LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested.");
    431         StreamingOutput result = null;
    432         try {
    433             final ComponentRegistry registry = findRegistry(profileId, new ProfileClosure());
    434             if (registry == null) {
    435                 return Response.status(Status.NOT_FOUND).entity("Id: " + profileId + " is not registered, cannot create data.").build();
    436             }
    437             ProfileDescription desc = registry.getProfileDescription(profileId);
    438             checkAndThrowDescription(desc, profileId);
    439             String fileName = desc.getName() + "." + rawType;
    440 
    441             if ("xml".equalsIgnoreCase(rawType)) {
    442                 result = new StreamingOutput() {
    443 
    444                     @Override
    445                     public void write(OutputStream output) throws IOException, WebApplicationException {
    446                         try {
    447                             registry.getMDProfileAsXml(profileId, output);
    448                         } catch (ComponentRegistryException e) {
    449                             LOG.warn("Could not retrieve component", e);
    450                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    451                         }
    452                     }
    453                 };
    454             } else if ("xsd".equalsIgnoreCase(rawType)) {
    455                 result = new StreamingOutput() {
    456 
    457                     @Override
    458                     public void write(OutputStream output) throws IOException, WebApplicationException {
    459                         try {
    460                             registry.getMDProfileAsXsd(profileId, output);
    461                         } catch (ComponentRegistryException e) {
    462                             LOG.warn("Could not retrieve component", e);
    463                             throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
    464                         }
    465                     }
    466                 };
    467             } else {
    468                 throw new WebApplicationException(Response.serverError().entity(
    469                         "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
    470             }
    471             return createDownloadResponse(result, fileName);
    472         } catch (ComponentRegistryException e) {
    473             LOG.info("Could not retrieve component", e);
    474             return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    475         }
     542        LOG.info("Profile with id: " + profileId + " and rawType:" + rawType + " is requested.");
     543        StreamingOutput result = null;
     544        try {
     545            final ComponentRegistry registry = findRegistry(profileId, new ProfileClosure());
     546            if (registry == null) {
     547                return Response.status(Status.NOT_FOUND).entity("Id: " + profileId + " is not registered, cannot create data.").build();
     548            }
     549            ProfileDescription desc = registry.getProfileDescription(profileId);
     550            checkAndThrowDescription(desc, profileId);
     551            String fileName = desc.getName() + "." + rawType;
     552
     553            if ("xml".equalsIgnoreCase(rawType)) {
     554                result = new StreamingOutput() {
     555
     556                    @Override
     557                    public void write(OutputStream output) throws IOException, WebApplicationException {
     558                        try {
     559                            registry.getMDProfileAsXml(profileId, output);
     560                        } catch (ComponentRegistryException e) {
     561                            LOG.warn("Could not retrieve component", e);
     562                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     563                        }
     564                    }
     565                };
     566            } else if ("xsd".equalsIgnoreCase(rawType)) {
     567                result = new StreamingOutput() {
     568
     569                    @Override
     570                    public void write(OutputStream output) throws IOException, WebApplicationException {
     571                        try {
     572                            registry.getMDProfileAsXsd(profileId, output);
     573                        } catch (ComponentRegistryException e) {
     574                            LOG.warn("Could not retrieve component", e);
     575                            throw new WebApplicationException(e, Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build());
     576                        }
     577                    }
     578                };
     579            } else {
     580                throw new WebApplicationException(Response.serverError().entity(
     581                        "unsupported rawType: " + rawType + " (only xml or xsd are supported)").build());
     582            }
     583            return createDownloadResponse(result, fileName);
     584        } catch (ComponentRegistryException e) {
     585            LOG.info("Could not retrieve component", e);
     586            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     587        }
    476588    }
    477589
    478590    private void checkAndThrowDescription(AbstractDescription desc, String id) {
    479         if (desc == null) {
    480             throw new WebApplicationException(Response.serverError().entity("Incorrect id:" + id + "cannot handle request").build());
    481         }
     591        if (desc == null) {
     592            throw new WebApplicationException(Response.serverError().entity("Incorrect id:" + id + "cannot handle request").build());
     593        }
    482594    }
    483595
    484596    private Response createDownloadResponse(StreamingOutput result, String fileName) {
    485         //Making response so it triggers browsers native save as dialog.
    486         Response response = Response.ok().type("application/x-download").header("Content-Disposition",
    487                 "attachment; filename=\"" + fileName + "\"").entity(result).build();
    488         return response;
     597        //Making response so it triggers browsers native save as dialog.
     598        Response response = Response.ok().type("application/x-download").header("Content-Disposition",
     599                "attachment; filename=\"" + fileName + "\"").entity(result).build();
     600        return response;
    489601
    490602    }
     
    495607    @Consumes("multipart/form-data")
    496608    public Response registerProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    497             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName,
    498             @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    499         Principal principal = checkAndGetUserPrincipal();
    500         UserCredentials userCredentials = getUserCredentials(principal);
    501         ProfileDescription desc = createNewProfileDescription();
    502         desc.setCreatorName(userCredentials.getDisplayName());
    503         desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    504         desc.setName(name);
    505         desc.setDescription(description);
    506         desc.setGroupName(group);
    507         desc.setDomainName(domainName);
    508         LOG.info("Trying to register Profile: " + desc);
    509         return register(input, desc, userCredentials, userspace, new NewAction());
     609            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group, @FormDataParam(DOMAIN_FORM_FIELD) String domainName,
     610            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     611        Principal principal = checkAndGetUserPrincipal();
     612        UserCredentials userCredentials = getUserCredentials(principal);
     613        ProfileDescription desc = createNewProfileDescription();
     614        desc.setCreatorName(userCredentials.getDisplayName());
     615        desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     616        desc.setName(name);
     617        desc.setDescription(description);
     618        desc.setGroupName(group);
     619        desc.setDomainName(domainName);
     620        LOG.info("Trying to register Profile: " + desc);
     621        return register(input, desc, userCredentials, userspace, new NewAction());
    510622    }
    511623
     
    515627    @Consumes("multipart/form-data")
    516628    public Response registerComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String name,
    517             @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
    518             @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    519         Principal principal = checkAndGetUserPrincipal();
    520         UserCredentials userCredentials = getUserCredentials(principal);
    521         ComponentDescription desc = createNewComponentDescription();
    522         desc.setCreatorName(userCredentials.getDisplayName());
    523         desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    524         desc.setName(name);
    525         desc.setDescription(description);
    526         desc.setGroupName(group);
    527         desc.setDomainName(domainName);
    528         LOG.info("Trying to register Component: " + desc);
    529         return register(input, desc, userCredentials, userspace, new NewAction());
     629            @FormDataParam(DESCRIPTION_FORM_FIELD) String description, @FormDataParam(GROUP_FORM_FIELD) String group,
     630            @FormDataParam(DOMAIN_FORM_FIELD) String domainName, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     631        Principal principal = checkAndGetUserPrincipal();
     632        UserCredentials userCredentials = getUserCredentials(principal);
     633        ComponentDescription desc = createNewComponentDescription();
     634        desc.setCreatorName(userCredentials.getDisplayName());
     635        desc.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     636        desc.setName(name);
     637        desc.setDescription(description);
     638        desc.setGroupName(group);
     639        desc.setDomainName(domainName);
     640        LOG.info("Trying to register Component: " + desc);
     641        return register(input, desc, userCredentials, userspace, new NewAction());
    530642    }
    531643
     
    534646    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    535647    public Response pingSession() {
    536         boolean stillActive = false;
    537         Principal userPrincipal = security.getUserPrincipal();
    538         LOG.info("ping by user: " + (userPrincipal == null ? "null" : userPrincipal.getName()));
    539         if (request != null) {
    540             if (userPrincipal != null && !ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
    541                 stillActive = !((HttpServletRequest) request).getSession().isNew();
    542             }
    543         }
    544         return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
     648        boolean stillActive = false;
     649        Principal userPrincipal = security.getUserPrincipal();
     650        LOG.info("ping by user: " + (userPrincipal == null ? "null" : userPrincipal.getName()));
     651        if (request != null) {
     652            if (userPrincipal != null && !ComponentRegistryFactory.ANONYMOUS_USER.equals(userPrincipal.getName())) {
     653                stillActive = !((HttpServletRequest) request).getSession().isNew();
     654            }
     655        }
     656        return Response.ok().entity("<session stillActive=\"" + stillActive + "\"/>").build();
    545657    }
    546658
    547659    private Response register(InputStream input, AbstractDescription desc, UserCredentials userCredentials, boolean userspace,
    548             RegisterAction action) {
    549         try {
    550             ComponentRegistry registry = getRegistry(userspace, userCredentials);
    551             DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
    552             MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
    553             RegisterResponse response = new RegisterResponse();
    554             response.setIsInUserSpace(userspace);
    555             validate(response, descriptionValidator, validator);
    556             if (response.getErrors().isEmpty()) {
    557                 CMDComponentSpec spec = validator.getCMDComponentSpec();
    558                 int returnCode = action.execute(desc, spec, response, registry);
    559                 if (returnCode == 0) {
    560                     response.setRegistered(true);
    561                     response.setDescription(desc);
    562                 } else {
    563                     response.setRegistered(false);
    564                     response.addError("Unable to register at this moment. Internal server error.");
    565                 }
    566             } else {
    567                 LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
    568                 response.setRegistered(false);
    569             }
    570             response.setIsProfile(desc.isProfile());
    571             return Response.ok(response).build();
    572         } finally {
    573             try {
    574                 input.close();//either we read the input or there was an exception, we need to close it.
    575             } catch (IOException e) {
    576                 LOG.error("Error when closing inputstream: ", e);
    577             }
    578         }
     660            RegisterAction action) {
     661        try {
     662            ComponentRegistry registry = getRegistry(userspace, userCredentials);
     663            DescriptionValidator descriptionValidator = new DescriptionValidator(desc);
     664            MDValidator validator = new MDValidator(input, desc, registry, getRegistry(true), componentRegistryFactory.getPublicRegistry());
     665            RegisterResponse response = new RegisterResponse();
     666            response.setIsInUserSpace(userspace);
     667            validate(response, descriptionValidator, validator);
     668            if (response.getErrors().isEmpty()) {
     669                CMDComponentSpec spec = validator.getCMDComponentSpec();
     670                int returnCode = action.execute(desc, spec, response, registry);
     671                if (returnCode == 0) {
     672                    response.setRegistered(true);
     673                    response.setDescription(desc);
     674                } else {
     675                    response.setRegistered(false);
     676                    response.addError("Unable to register at this moment. Internal server error.");
     677                }
     678            } else {
     679                LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
     680                response.setRegistered(false);
     681            }
     682            response.setIsProfile(desc.isProfile());
     683            return Response.ok(response).build();
     684        } finally {
     685            try {
     686                input.close();//either we read the input or there was an exception, we need to close it.
     687            } catch (IOException e) {
     688                LOG.error("Error when closing inputstream: ", e);
     689            }
     690        }
    579691    }
    580692
    581693    private ComponentDescription createNewComponentDescription() {
    582         ComponentDescription desc = ComponentDescription.createNewDescription();
    583         desc.setHref(createXlink(desc.getId()));
    584         return desc;
     694        ComponentDescription desc = ComponentDescription.createNewDescription();
     695        desc.setHref(createXlink(desc.getId()));
     696        return desc;
    585697    }
    586698
    587699    private ProfileDescription createNewProfileDescription() {
    588         ProfileDescription desc = ProfileDescription.createNewDescription();
    589         desc.setHref(createXlink(desc.getId()));
    590         return desc;
     700        ProfileDescription desc = ProfileDescription.createNewDescription();
     701        desc.setHref(createXlink(desc.getId()));
     702        return desc;
    591703    }
    592704
    593705    private String createXlink(String id) {
    594         URI uri = uriInfo.getRequestUriBuilder().path(id).build();
    595         return uri.toString();
     706        URI uri = uriInfo.getRequestUriBuilder().path(id).build();
     707        return uri.toString();
    596708    }
    597709
    598710    private void validate(RegisterResponse response, Validator... validators) {
    599         for (Validator validator : validators) {
    600             if (!validator.validate()) {
    601                 for (String error : validator.getErrorMessages()) {
    602                     response.addError(error);
    603                 }
    604             }
    605         }
     711        for (Validator validator : validators) {
     712            if (!validator.validate()) {
     713                for (String error : validator.getErrorMessages()) {
     714                    response.addError(error);
     715                }
     716            }
     717        }
    606718    }
    607719
     
    610722     */
    611723    public void setComponentRegistryFactory(ComponentRegistryFactory componentRegistryFactory) {
    612         this.componentRegistryFactory = componentRegistryFactory;
     724        this.componentRegistryFactory = componentRegistryFactory;
    613725    }
    614726}
Note: See TracChangeset for help on using the changeset viewer.