GalleryDescription.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * blueMarine II: Semantic Media Centre
  5.  * http://tidalwave.it/projects/bluemarine2
  6.  *
  7.  * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *********************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  12.  * the License. You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/bluemarine2-src
  23.  * git clone https://github.com/tidalwave-it/bluemarine2-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.bluemarine2.service.stoppingdown.impl;

  28. import javax.annotation.Nonnull;
  29. import javax.annotation.concurrent.Immutable;
  30. import java.util.Collection;
  31. import java.util.function.BiFunction;
  32. import java.nio.file.Path;
  33. import java.nio.file.Paths;
  34. import it.tidalwave.bluemarine2.model.MediaFolder;
  35. import it.tidalwave.bluemarine2.model.VirtualMediaFolder;
  36. import it.tidalwave.bluemarine2.model.VirtualMediaFolder.EntityCollectionFactory;
  37. import it.tidalwave.bluemarine2.model.spi.PathAwareEntity;
  38. import lombok.EqualsAndHashCode;
  39. import lombok.Getter;
  40. import lombok.RequiredArgsConstructor;
  41. import lombok.ToString;

  42. /***********************************************************************************************************************
  43.  *
  44.  * @author  Fabrizio Giudici
  45.  *
  46.  **********************************************************************************************************************/
  47. @Immutable
  48. @RequiredArgsConstructor @Getter @EqualsAndHashCode @ToString
  49. public class GalleryDescription
  50.   {
  51.     @Nonnull
  52.     private final String displayName;

  53.     @Nonnull
  54.     private final String url;

  55.     /*******************************************************************************************************************
  56.      *
  57.      * Creates a {@link MediaFolder} with the given parent and the children provided by a factory.
  58.      *
  59.      * @param   parent              the parent folder
  60.      * @param   entitiesFactory     a function which, given the parent and a URL, provides the entities
  61.      * @return                      the folder
  62.      *
  63.      ******************************************************************************************************************/
  64.     // FIXME: even though the finder is retrieved later, through the factory, the translation to DIDL does compute
  65.     // the finder because it calls the count() for the children count
  66.     @Nonnull
  67.     public PathAwareEntity createFolder (@Nonnull final MediaFolder parent,
  68.                                          @Nonnull final BiFunction<MediaFolder, String, Collection<PathAwareEntity>> entitiesFactory)
  69.       {
  70.         final Path path = Paths.get(url.replaceAll("^.*(themes|diary\\/[0-9]{4})\\/(.*)\\/images\\.xml", "$2"));
  71.         final EntityCollectionFactory ecf = p -> entitiesFactory.apply(p, url);
  72.         return new VirtualMediaFolder(parent, path, displayName, ecf);
  73.       }
  74.   }