/**
  * Register a module name and type with its Maven coordinates.
  *
  * @param type module type
  * @param name module name
  * @param coordinates Maven coordinates for the module artifact
  * @param force if {@code true}, overwrites a pre-existing registration
  */
 @RequestMapping(value = "/{type}/{name}", method = RequestMethod.POST)
 @ResponseStatus(HttpStatus.CREATED)
 public void register(
     @PathVariable("type") ArtifactType type,
     @PathVariable("name") String name,
     @RequestParam("coordinates") String coordinates,
     @RequestParam(value = "force", defaultValue = "false") boolean force) {
   Assert.isTrue(type != ArtifactType.library, "Only modules are supported by this endpoint");
   if (!force && registry.find(name, type) != null) {
     return;
   }
   registry.save(new ArtifactRegistration(name, type, ArtifactCoordinates.parse(coordinates)));
 }
 /**
  * Unregister a module name and type.
  *
  * @param type the module type
  * @param name the module name
  */
 @RequestMapping(value = "/{type}/{name}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.OK)
 public void unregister(
     @PathVariable("type") ArtifactType type, @PathVariable("name") String name) {
   Assert.isTrue(type != ArtifactType.library, "Only modules are supported by this endpoint");
   registry.delete(name, type);
 }
  /** List module registrations. */
  @RequestMapping(method = RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  public PagedResources<? extends ModuleRegistrationResource> list(
      PagedResourcesAssembler<ArtifactRegistration> assembler,
      @RequestParam(value = "type", required = false) ArtifactType type,
      @RequestParam(value = "detailed", defaultValue = "false") boolean detailed) {

    List<ArtifactRegistration> list = new ArrayList<>(registry.findAll());
    for (Iterator<ArtifactRegistration> iterator = list.iterator(); iterator.hasNext(); ) {
      ArtifactType artifactType = iterator.next().getType();
      if ((type != null && artifactType != type) || artifactType == ArtifactType.library) {
        iterator.remove();
      }
    }
    Collections.sort(list);
    return assembler.toResource(new PageImpl<>(list), moduleAssembler);
  }
  /**
   * Retrieve detailed information about a particular module.
   *
   * @param type module type
   * @param name module name
   * @return detailed module information
   */
  @RequestMapping(value = "/{type}/{name}", method = RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  public DetailedModuleRegistrationResource info(
      @PathVariable("type") ArtifactType type, @PathVariable("name") String name) {
    Assert.isTrue(type != ArtifactType.library, "Only modules are supported by this endpoint");
    ArtifactRegistration registration = registry.find(name, type);
    if (registration == null) {
      return null;
    }
    DetailedModuleRegistrationResource result =
        new DetailedModuleRegistrationResource(moduleAssembler.toResource(registration));
    Resource resource = moduleResolver.resolve(adapt(registration.getCoordinates()));

    List<ConfigurationMetadataProperty> properties =
        moduleConfigurationMetadataResolver.listProperties(resource);
    for (ConfigurationMetadataProperty property : properties) {
      result.addOption(property);
    }
    return result;
  }