Example #1
0
  /**
   * Recreates a registry entry
   *
   * @param entryStream the input stream corresponding to the content of the registry entry
   * @param groupName the relative path to the group
   * @param createIfNotExist if set to true, it will try to create the registry if it doesn't exist
   *     yet
   * @request {code} "entryStream" : the input stream corresponding to the content of the registry
   *     entry {code} Example : {code:xml} <Audit jcr:primaryType="exo:registryEntry">
   *     <adminIdentity jcr:primaryType="nt:unstructured" value="*:/Platform/Administrators"/>
   *     </Audit> {code} @LevelAPI Experimental
   */
  @PUT
  @Path("/{groupName:.+}")
  @Consumes(MediaType.APPLICATION_XML)
  public Response recreateEntry(
      InputStream entryStream,
      @PathParam("groupName") String groupName,
      @Context UriInfo uriInfo,
      @QueryParam("createIfNotExist") boolean createIfNotExist) {

    SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null);
    try {
      RegistryEntry entry = RegistryEntry.parse(entryStream);
      if (createIfNotExist) {
        regService.updateEntry(sessionProvider, normalizePath(groupName), entry);
      } else {
        regService.recreateEntry(sessionProvider, normalizePath(groupName), entry);
      }
      URI location = uriInfo.getRequestUriBuilder().path(entry.getName()).build();
      return Response.created(location).build();
    } catch (IllegalArgumentException e) {
      LOG.error("Re-create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (IOException e) {
      LOG.error("Re-create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (SAXException e) {
      LOG.error("Re-create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (ParserConfigurationException e) {
      LOG.error("Re-create registry entry failed", e);
      throw new WebApplicationException(e);
    } catch (RepositoryException e) {
      LOG.error("Re-create registry entry failed", e);
      throw new WebApplicationException(e);
    }
  }