diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/Zebedee.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/Zebedee.java index ca488a461..bfc871585 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/Zebedee.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/Zebedee.java @@ -11,6 +11,7 @@ import com.github.onsdigital.zebedee.model.Collection; import com.github.onsdigital.zebedee.model.Collections; import com.github.onsdigital.zebedee.model.Content; +import com.github.onsdigital.zebedee.model.PublishedContent; import com.github.onsdigital.zebedee.model.ZebedeeCollectionReader; import com.github.onsdigital.zebedee.model.encryption.EncryptionKeyFactory; import com.github.onsdigital.zebedee.model.publishing.PublishedCollections; @@ -19,8 +20,7 @@ import com.github.onsdigital.zebedee.service.DatasetService; import com.github.onsdigital.zebedee.service.ImageService; import com.github.onsdigital.zebedee.service.KafkaService; -import com.github.onsdigital.zebedee.service.ServiceStore; -import com.github.onsdigital.zebedee.service.ServiceStoreImpl; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import com.github.onsdigital.zebedee.session.model.Session; import com.github.onsdigital.zebedee.session.service.Sessions; import com.github.onsdigital.zebedee.teams.service.TeamsService; @@ -36,6 +36,7 @@ import java.nio.file.Paths; import java.util.Optional; +import static com.github.onsdigital.zebedee.ZebedeeConfiguration.COLLECTIONS; import static com.github.onsdigital.zebedee.configuration.Configuration.isVerificationEnabled; import static com.github.onsdigital.zebedee.exceptions.DeleteContentRequestDeniedException.beingEditedByAnotherCollectionError; import static com.github.onsdigital.zebedee.exceptions.DeleteContentRequestDeniedException.beingEditedByThisCollectionError; @@ -44,36 +45,11 @@ import static com.github.onsdigital.zebedee.logging.CMSLogEvent.info; public class Zebedee { - public static final String PUBLISHED = "master"; - public static final String COLLECTIONS = "collections"; - public static final String PUBLISHED_COLLECTIONS = "publish-log"; - public static final String ZEBEDEE = "zebedee"; - public static final String USERS = "users"; - public static final String SESSIONS = "sessions"; - public static final String PERMISSIONS = "permissions"; - public static final String TEAMS = "teams"; - public static final String LAUNCHPAD = "launchpad"; - public static final String APPLICATION_KEYS = "application-keys"; - public static final String SERVICES = "services"; - public static final String KEYRING = "keyring"; - - private final Path publishedCollectionsPath; - private final Path collectionsPath; - private final Path usersPath; - private final Path sessionsPath; - private final Path permissionsPath; - private final Path teamsPath; - private final Path redirectPath; - private final Path servicePath; - private final Path keyRingPath; - private final VerificationAgent verificationAgent; private final PublishedCollections publishedCollections; private final Collections collections; - private final Content published; + private final PublishedContent published; private final CollectionKeyCache schedulerKeyCache; - private final Path publishedContentPath; - private final Path path; private final PermissionsService permissionsService; private final CollectionKeyring collectionKeyring; private final EncryptionKeyFactory encryptionKeyFactory; @@ -85,10 +61,12 @@ public class Zebedee { private final DatasetService datasetService; private final ImageService imageService; private final KafkaService kafkaService; - private final ServiceStoreImpl serviceStoreImpl; + private final ServiceStore serviceStore; private final StartUpNotifier startUpNotifier; private final Notifier slackNotifier; + private final Path path; + /** * Create a new instance of Zebedee setting. * @@ -96,7 +74,6 @@ public class Zebedee { */ public Zebedee(ZebedeeConfiguration cfg) { this.path = cfg.getZebedeePath(); - this.publishedContentPath = cfg.getPublishedContentPath(); this.sessions = cfg.getSessions(); this.schedulerKeyCache = cfg.getSchedulerKeyringCache(); this.permissionsService = cfg.getPermissionsService(); @@ -106,23 +83,14 @@ public Zebedee(ZebedeeConfiguration cfg) { this.publishedCollections = cfg.getPublishCollections(); this.teamsService = cfg.getTeamsService(); this.usersService = cfg.getUsersService(); - this.verificationAgent = cfg.getVerificationAgent(isVerificationEnabled(), this); + this.verificationAgent = cfg.getVerificationAgent(); this.datasetService = cfg.getDatasetService(); this.imageService = cfg.getImageService(); this.kafkaService = cfg.getKafkaService(); - this.serviceStoreImpl = cfg.getServiceStore(); + this.serviceStore = cfg.getServiceStore(); this.collectionKeyring = cfg.getCollectionKeyring(); this.encryptionKeyFactory = cfg.getEncryptionKeyFactory(); - this.collectionsPath = cfg.getCollectionsPath(); - this.publishedCollectionsPath = cfg.getPublishedCollectionsPath(); - this.usersPath = cfg.getUsersPath(); - this.sessionsPath = cfg.getSessionsPath(); - this.permissionsPath = cfg.getPermissionsPath(); - this.teamsPath = cfg.getTeamsPath(); - this.redirectPath = cfg.getRedirectPath(); - this.servicePath = cfg.getServicePath(); - this.keyRingPath = cfg.getKeyRingPath(); this.startUpNotifier = cfg.getStartUpNotifier(); this.slackNotifier = cfg.getSlackNotifier(); } @@ -325,11 +293,7 @@ public PermissionsService getPermissionsService() { return this.permissionsService; } - public Path getPublishedContentPath() { - return this.publishedContentPath; - } - - public Content getPublished() { + public PublishedContent getPublished() { return this.published; } @@ -374,15 +338,7 @@ public KafkaService getKafkaService() { } public ServiceStore getServiceStore() { - return serviceStoreImpl; - } - - public Path getServicePath() { - return servicePath; - } - - public Path getKeyRingPath() { - return keyRingPath; + return serviceStore; } public CollectionKeyring getCollectionKeyring() { diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/ZebedeeConfiguration.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/ZebedeeConfiguration.java index 4072119ab..b0f502a87 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/ZebedeeConfiguration.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/ZebedeeConfiguration.java @@ -13,12 +13,12 @@ import com.github.onsdigital.zebedee.keyring.CollectionKeyCache; import com.github.onsdigital.zebedee.keyring.CollectionKeyStore; import com.github.onsdigital.zebedee.keyring.CollectionKeyring; -import com.github.onsdigital.zebedee.keyring.KeyringException; import com.github.onsdigital.zebedee.keyring.central.CollectionKeyCacheImpl; import com.github.onsdigital.zebedee.keyring.central.CollectionKeyStoreImpl; import com.github.onsdigital.zebedee.keyring.central.CollectionKeyringImpl; import com.github.onsdigital.zebedee.model.Collections; import com.github.onsdigital.zebedee.model.Content; +import com.github.onsdigital.zebedee.model.PublishedContent; import com.github.onsdigital.zebedee.model.RedirectTablePartialMatch; import com.github.onsdigital.zebedee.model.encryption.EncryptionKeyFactory; import com.github.onsdigital.zebedee.model.encryption.EncryptionKeyFactoryImpl; @@ -37,8 +37,10 @@ import com.github.onsdigital.zebedee.service.KafkaService; import com.github.onsdigital.zebedee.service.KafkaServiceImpl; import com.github.onsdigital.zebedee.service.NoOpKafkaService; -import com.github.onsdigital.zebedee.service.ServiceStoreImpl; +import com.github.onsdigital.zebedee.service.ServiceSupplier; import com.github.onsdigital.zebedee.service.ZebedeeDatasetService; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStoreImpl; import com.github.onsdigital.zebedee.session.service.JWTSessionsServiceImpl; import com.github.onsdigital.zebedee.session.service.Sessions; import com.github.onsdigital.zebedee.session.service.SessionsServiceImpl; @@ -52,9 +54,9 @@ import com.github.onsdigital.zebedee.user.service.StubbedUsersServiceImpl; import com.github.onsdigital.zebedee.user.service.UsersService; import com.github.onsdigital.zebedee.user.service.UsersServiceImpl; +import com.github.onsdigital.zebedee.user.store.UserStore; import com.github.onsdigital.zebedee.user.store.UserStoreFileSystemImpl; import com.github.onsdigital.zebedee.util.slack.NopNotifierImpl; -import com.github.onsdigital.zebedee.util.slack.NopSlackClientImpl; import com.github.onsdigital.zebedee.util.slack.NopStartUpNotifier; import com.github.onsdigital.zebedee.util.slack.Notifier; import com.github.onsdigital.zebedee.util.slack.SlackNotifier; @@ -70,25 +72,16 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import java.util.function.Supplier; +import java.util.Map; import static com.github.onsdigital.logging.v2.event.SimpleEvent.error; import static com.github.onsdigital.logging.v2.event.SimpleEvent.info; import static com.github.onsdigital.logging.v2.event.SimpleEvent.warn; -import static com.github.onsdigital.zebedee.Zebedee.COLLECTIONS; -import static com.github.onsdigital.zebedee.Zebedee.KEYRING; -import static com.github.onsdigital.zebedee.Zebedee.PERMISSIONS; -import static com.github.onsdigital.zebedee.Zebedee.PUBLISHED; -import static com.github.onsdigital.zebedee.Zebedee.PUBLISHED_COLLECTIONS; -import static com.github.onsdigital.zebedee.Zebedee.SERVICES; -import static com.github.onsdigital.zebedee.Zebedee.SESSIONS; -import static com.github.onsdigital.zebedee.Zebedee.TEAMS; -import static com.github.onsdigital.zebedee.Zebedee.USERS; -import static com.github.onsdigital.zebedee.Zebedee.ZEBEDEE; import static com.github.onsdigital.zebedee.configuration.CMSFeatureFlags.cmsFeatureFlags; import static com.github.onsdigital.zebedee.configuration.Configuration.getCognitoKeyIdPairs; import static com.github.onsdigital.zebedee.configuration.Configuration.getDatasetAPIAuthToken; import static com.github.onsdigital.zebedee.configuration.Configuration.getDatasetAPIURL; +import static com.github.onsdigital.zebedee.configuration.Configuration.getDefaultVerificationUrl; import static com.github.onsdigital.zebedee.configuration.Configuration.getImageAPIURL; import static com.github.onsdigital.zebedee.configuration.Configuration.getKafkaContentPublishedTopic; import static com.github.onsdigital.zebedee.configuration.Configuration.getKafkaURL; @@ -96,6 +89,8 @@ import static com.github.onsdigital.zebedee.configuration.Configuration.getKeyringSecretKey; import static com.github.onsdigital.zebedee.configuration.Configuration.getServiceAuthToken; import static com.github.onsdigital.zebedee.configuration.Configuration.getSlackSupportChannelID; +import static com.github.onsdigital.zebedee.configuration.Configuration.getSlackToken; +import static com.github.onsdigital.zebedee.configuration.Configuration.isVerificationEnabled; import static com.github.onsdigital.zebedee.configuration.Configuration.slackChannelsToNotfiyOnStartUp; import static com.github.onsdigital.zebedee.permissions.store.PermissionsStoreFileSystemImpl.initialisePermissions; import static org.apache.commons.lang3.StringUtils.isEmpty; @@ -105,28 +100,29 @@ * directories required by zebedee, create the service instances it requires etc. */ public class ZebedeeConfiguration { - private Path rootPath; - private Path zebedeePath; - private Path publishedContentPath; - private Path publishedCollectionsPath; - private Path collectionsPath; - private Path usersPath; - private Path sessionsPath; - private Path permissionsPath; - private Path teamsPath; - private Path redirectPath; - private Path servicePath; - private Path keyRingPath; + public static final String PUBLISHED = "master"; + public static final String COLLECTIONS = "collections"; + public static final String PUBLISHED_COLLECTIONS = "publish-log"; + public static final String ZEBEDEE = "zebedee"; + public static final String USERS = "users"; + public static final String SESSIONS = "sessions"; + public static final String PERMISSIONS = "permissions"; + public static final String TEAMS = "teams"; + public static final String LAUNCHPAD = "launchpad"; + public static final String APPLICATION_KEYS = "application-keys"; + public static final String SERVICES = "services"; + public static final String KEYRING = "keyring"; + private boolean useVerificationAgent; + private Path zebedeePath; private PublishedCollections publishedCollections; private Collections collections; - private Content published; + private PublishedContent published; private PermissionsService permissionsService; private UsersService usersService; private TeamsService teamsService; private Sessions sessions; private DataIndex dataIndex; - private PermissionsStore permissionsStore; private DatasetService datasetService; private ImageService imageService; private KafkaService kafkaService; @@ -134,8 +130,9 @@ public class ZebedeeConfiguration { private CollectionKeyCache schedulerKeyCache; private EncryptionKeyFactory encryptionKeyFactory; private StartUpNotifier startUpNotifier; - private SlackClient slackClient; private Notifier slackNotifier; + private ServiceStore serviceStore; + private VerificationAgent verificationAgent; /** * Create a new configuration object. @@ -151,136 +148,390 @@ public ZebedeeConfiguration(Path rootPath, boolean enableVerificationAgent) thro throw new IllegalArgumentException("zebedee root directory doesn't not exist." + rootPath.toAbsolutePath()); } - // Create the zebedee file system structure - this.rootPath = rootPath; - this.zebedeePath = createDir(rootPath, ZEBEDEE); - this.publishedContentPath = createDir(zebedeePath, PUBLISHED); - this.collectionsPath = createDir(zebedeePath, COLLECTIONS); - this.publishedCollectionsPath = createDir(zebedeePath, PUBLISHED_COLLECTIONS); - this.usersPath = createDir(zebedeePath, USERS); - this.sessionsPath = createDir(zebedeePath, SESSIONS); - this.permissionsPath = createDir(zebedeePath, PERMISSIONS); - this.teamsPath = createDir(zebedeePath, TEAMS); - this.redirectPath = this.publishedContentPath.resolve(Content.REDIRECT); - this.servicePath = createDir(zebedeePath, SERVICES); - this.keyRingPath = createDir(zebedeePath, KEYRING); - if (!Files.exists(redirectPath)) { - Files.createFile(redirectPath); - } this.useVerificationAgent = enableVerificationAgent; + // Create the zebedee file system structure + zebedeePath = createDir(rootPath, ZEBEDEE); + // Create the services and objects... - this.dataIndex = new DataIndex(new FileSystemContentReader(publishedContentPath)); - this.publishedCollections = new PublishedCollections(publishedCollectionsPath); - this.encryptionKeyFactory = new EncryptionKeyFactoryImpl(); + // Initialise the teams service (uses a service supplier to break circular dependency with permissions service) + initTeamsService(zebedeePath, this::getPermissionsService); + + // Initialise the permissions service + initPermissionsService(zebedeePath, teamsService); + + // Initialise the users service + initUsersService(zebedeePath, permissionsService); + + // Initialise the sessions service + initSessionsService(zebedeePath, getCognitoKeyIdPairs()); + + // Initialise published content services (data index and published content reader) + initPublishedContentServices(zebedeePath); + + // Initialise collection content services + initCollectionServices(zebedeePath, permissionsService); + + // Initialise the collection keyring and scheduler cache. + initCollectionKeyring(zebedeePath, permissionsService, collections); + + // Initialise the post publish verification service + initVerificationAgent(publishedCollections, getDefaultVerificationUrl()); + + // Initialise Dataset API integration + initDatasetService(getDatasetAPIURL(), getDatasetAPIAuthToken(), getServiceAuthToken()); + + // Initialise Image service + initImageService(getImageAPIURL(), getServiceAuthToken()); + + // Initialise the kafka producer for producing content published events for use by services such as search indexing + initKafkaService(getKafkaURL(), getKafkaContentPublishedTopic()); + + // Initialise service token store + initServiceTokenStore(zebedeePath); + + // Initialise slack integration + initSlackIntegration(getSlackToken(), slackChannelsToNotfiyOnStartUp(), getSlackSupportChannelID()); + + info().data("root_path", rootPath.toString()) + .data("zebedee_path", zebedeePath.toString()) + .data("enable_verification_agent", useVerificationAgent) + .log("zebedee configuration creation complete"); + } + + + public Path getZebedeePath() { + return zebedeePath; + } + + public PublishedContent getPublished() { + return this.published; + } + + public DataIndex getDataIndex() { + return this.dataIndex; + } + + public Collections getCollections() { + return this.collections; + } + + public PublishedCollections getPublishCollections() { + return this.publishedCollections; + } + + public Sessions getSessions() { + return this.sessions; + } + + public PermissionsService getPermissionsService() { + return this.permissionsService; + } + + public TeamsService getTeamsService() { + return this.teamsService; + } + + public UsersService getUsersService() { + return this.usersService; + } + + public VerificationAgent getVerificationAgent() { + return verificationAgent; + } + + public DatasetService getDatasetService() { + return datasetService; + } + + public ImageService getImageService() { + return imageService; + } + + public KafkaService getKafkaService() { + return kafkaService; + } - // TODO: Remove after migration to JWT sessions is complete + public ServiceStore getServiceStore() { + return serviceStore; + } + + public CollectionKeyring getCollectionKeyring() { + return collectionKeyring; + } + + public EncryptionKeyFactory getEncryptionKeyFactory() { + return encryptionKeyFactory; + } + + public CollectionKeyCache getSchedulerKeyringCache() { + return schedulerKeyCache; + } + + public StartUpNotifier getStartUpNotifier() { + return startUpNotifier; + } + + public Notifier getSlackNotifier() { + return slackNotifier; + } + + /** + * Initialise the teams service. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @param permissionsServiceServiceSupplier a {@link ServiceSupplier} to supply the {@link PermissionsService} without + * creating a circular dependency + * @throws IOException If a filesystem error occurs. + * + * TODO: Remove after migration to JWT sessions is complete + */ + private void initTeamsService(Path zebedeePath, + ServiceSupplier permissionsServiceServiceSupplier) + throws IOException { + + Path teamsPath = createDir(zebedeePath, TEAMS); if (cmsFeatureFlags().isJwtSessionsEnabled()) { this.teamsService = new StubbedTeamsServiceImpl(); + info().log("JWT sessions enabled: stubbed teams service initialised"); } else { this.teamsService = new TeamsServiceImpl( - new TeamsStoreFileSystemImpl(teamsPath), this::getPermissionsService); - } + new TeamsStoreFileSystemImpl(teamsPath), permissionsServiceServiceSupplier); - this.published = createPublished(); + info().data("teams_path", teamsPath.toString()) + .log("legacy teams service initialised"); + } + } + /** + * Initialise the permissions service. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @param teamsService the {@link TeamsService} + * @throws IOException If a filesystem error occurs. + */ + private void initPermissionsService(Path zebedeePath, TeamsService teamsService) throws IOException { + Path permissionsPath = createDir(zebedeePath, PERMISSIONS); initialisePermissions(permissionsPath); - this.permissionsStore = new PermissionsStoreFileSystemImpl(permissionsPath); + PermissionsStore permissionsStore = new PermissionsStoreFileSystemImpl(permissionsPath); PermissionsServiceImpl legacyPermissionsService = new PermissionsServiceImpl(permissionsStore, this::getTeamsService); JWTPermissionsServiceImpl jwtPermissionsService = new JWTPermissionsServiceImpl(permissionsStore); this.permissionsService = new PermissionsServiceProxy(cmsFeatureFlags().isJwtSessionsEnabled(), legacyPermissionsService, jwtPermissionsService); - VersionsService versionsService = new VersionsServiceImpl(); - this.collections = new Collections(collectionsPath, permissionsService, versionsService, published); + info().data("permissions_path", permissionsPath.toString()) + .data("jwt_sessions_enabled", cmsFeatureFlags().isJwtSessionsEnabled()) + .log("permissions service initialised"); + } - // TODO: Remove after migration to JWT sessions is complete + /** + * Initialise the users service. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @param permissionsService the {@link PermissionsService} + * @throws IOException If a filesystem error occurs. + * + * TODO: Remove after migration to JWT sessions is complete + */ + private void initUsersService(Path zebedeePath, PermissionsService permissionsService) throws IOException { + Path usersPath = createDir(zebedeePath, USERS); if (cmsFeatureFlags().isJwtSessionsEnabled()) { this.usersService = StubbedUsersServiceImpl.getInstance(); + info().log("JWT sessions enabled: stubbed users service initialised"); } else { - this.usersService = UsersServiceImpl.getInstance( - new UserStoreFileSystemImpl(this.usersPath), permissionsService); + UserStore usersStore = new UserStoreFileSystemImpl(usersPath); + this.usersService = UsersServiceImpl.getInstance(usersStore, permissionsService); + + info().data("users_path", usersPath.toString()) + .log("legacy users service initialised"); } + } - // Configure the sessions + /** + * Initialise the sessions service. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @param cognitoKeyIdPairs the cognito public signing keys + * @throws IOException If a filesystem error occurs. + */ + private void initSessionsService(Path zebedeePath, Map cognitoKeyIdPairs) throws IOException { + Path sessionsPath = createDir(zebedeePath, SESSIONS); if (cmsFeatureFlags().isJwtSessionsEnabled()) { JWTHandler jwtHandler = new JWTHandlerImpl(); this.sessions = new JWTSessionsServiceImpl(jwtHandler, getCognitoKeyIdPairs()); + info().log("JWT sessions service initialised"); } else { SessionsStore sessionsStore = new SessionsStoreImpl(sessionsPath); this.sessions = new ThreadLocalSessionsServiceImpl(sessionsStore, permissionsService, teamsService); + info().data("sessions_path", sessionsPath.toString()) + .log("legacy sessions service initialised"); + } + } + + /** + * Initialise the central keyring used to store the encryption keys for the collection content. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @param permissionsService the {@link PermissionsService} + * @param collections the {@link Collections} service + * @throws IOException If a filesystem error occurs. + */ + private void initCollectionKeyring(Path zebedeePath, PermissionsService permissionsService, Collections collections) + throws IOException { + + Path keyringPath = createDir(zebedeePath, KEYRING); + + CollectionKeyStore keyStore = new CollectionKeyStoreImpl( + keyringPath, getKeyringSecretKey(), getKeyringInitVector()); + + CollectionKeyCacheImpl.init(keyStore); + CollectionKeyCache collectionKeyCache = CollectionKeyCacheImpl.getInstance(); + + this.schedulerKeyCache = collectionKeyCache; + + CollectionKeyringImpl.init(collectionKeyCache, permissionsService, collections); + this.collectionKeyring = CollectionKeyringImpl.getInstance(); + + info().data("keyring_path", keyringPath.toString()) + .log("collection keyring initialised"); + } + + /** + * Initialise content services (i.e. data index and published content reader). + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @throws IOException If a filesystem error occurs. + */ + private void initPublishedContentServices(Path zebedeePath) throws IOException { + Path publishedContentPath = createDir(zebedeePath, PUBLISHED); + + Path redirectPath = publishedContentPath.resolve(Content.REDIRECT); + if (!Files.exists(redirectPath)) { + Files.createFile(redirectPath); } - // Init the collection keyring and scheduler cache. - initCollectionKeyring(); + published = new PublishedContent(publishedContentPath); + published.setRedirects(new RedirectTablePartialMatch(published)); + + this.dataIndex = new DataIndex(new FileSystemContentReader(publishedContentPath)); + + info().data("published_content_path", publishedContentPath.toString()) + .log("published content services initialised"); + } + /** + * Initialise the collection content services. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @param permissionsService the {@link PermissionsService} + * @throws IOException If a filesystem error occurs. + */ + private void initCollectionServices(Path zebedeePath, PermissionsService permissionsService) + throws IOException { + + Path collectionsPath = createDir(zebedeePath, COLLECTIONS); + Path publishedCollectionsPath = createDir(zebedeePath, PUBLISHED_COLLECTIONS); + + this.publishedCollections = new PublishedCollections(publishedCollectionsPath); + this.encryptionKeyFactory = new EncryptionKeyFactoryImpl(); + + VersionsService versionsService = new VersionsServiceImpl(); + this.collections = new Collections(collectionsPath, permissionsService, versionsService, published); + + info().data("collections_path", collectionsPath.toString()) + .data("published_collections_path", publishedCollectionsPath.toString()) + .log("collection services initialised"); + } + + /** + * Initialise the dataset service responsible for integration with the dataset API for publishing datasets. + * + * @param datasetAPIURL the base dataset API url + * @param datasetAPIAuthToken the deprecated service to service shared secret token + * @param serviceAuthToken zebedee's service auth token for use in authenticating requests to the dataset API + */ + private void initDatasetService(String datasetAPIURL, String datasetAPIAuthToken, String serviceAuthToken) { DatasetClient datasetClient; try { - datasetClient = new DatasetAPIClient(getDatasetAPIURL(), getDatasetAPIAuthToken(), getServiceAuthToken()); + datasetClient = new DatasetAPIClient(datasetAPIURL, datasetAPIAuthToken, serviceAuthToken); } catch (URISyntaxException e) { error().logException(e, "failed to initialise dataset api client - invalid URI"); - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } datasetService = new ZebedeeDatasetService(datasetClient); + info().data("dataset_api_url", datasetAPIURL) + .log("dataset api client service initialised"); + } + + /** + * Initialise the image service which provides integration with the Image API for publishing images. + * + * @param imageAPIURL the image API base url + * @param serviceAuthToken zebedee's service auth token for use in authenticating requests to the image API + */ + private void initImageService(String imageAPIURL, String serviceAuthToken) { ImageClient imageClient; try { - imageClient = new ImageAPIClient(getImageAPIURL(), getServiceAuthToken()); + imageClient = new ImageAPIClient(imageAPIURL, serviceAuthToken); } catch (URISyntaxException e) { error().logException(e, "failed to initialise image api client - invalid URI"); - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } imageService = new ImageServiceImpl(imageClient); - if (cmsFeatureFlags().isKafkaEnabled()) { + info().data("image_api_url", imageAPIURL) + .log("image api client service initialised"); + } - KafkaClient kafkaClient = new KafkaClientImpl(getKafkaURL(), getKafkaContentPublishedTopic()); + /** + * Initialise the kafka producer service. This service produces content published events for consumption by services + * such as search indexing + * + * @param kafkaURL the kafka URL + * @param kafkaContentPublishedTopic the topic name on which to produce content published events + */ + private void initKafkaService(String kafkaURL, String kafkaContentPublishedTopic) { + if (cmsFeatureFlags().isKafkaEnabled()) { + KafkaClient kafkaClient = new KafkaClientImpl(kafkaURL, kafkaContentPublishedTopic); kafkaService = new KafkaServiceImpl(kafkaClient); } else { kafkaService = new NoOpKafkaService(); } - initSlackIntegration(); - - info().data("root_path", rootPath.toString()) - .data("zebedee_path", zebedeePath.toString()) - .data("keyring_path", keyRingPath.toString()) - .data("published_content_path", publishedContentPath.toString()) - .data("collections_path", collectionsPath.toString()) - .data("published_collections_path", publishedCollectionsPath.toString()) - .data("users_path", usersPath.toString()) - .data("sessions_path", sessionsPath.toString()) - .data("permissions_path", permissionsPath.toString()) - .data("teams_path", teamsPath.toString()) - .data("services_path", servicePath.toString()) - .data("enable_verification_agent", useVerificationAgent) - .data("sessions_api_enabled", cmsFeatureFlags().isSessionAPIEnabled()) - .log("zebedee configuration creation complete"); + info().data("kafka_url", kafkaURL) + .data("kafka_content_published_topic", kafkaContentPublishedTopic) + .log("kafka producer service initialised"); } - private void initCollectionKeyring() throws KeyringException { - CollectionKeyStore keyStore = new CollectionKeyStoreImpl( - getKeyRingPath(), getKeyringSecretKey(), getKeyringInitVector()); - - CollectionKeyCacheImpl.init(keyStore); - CollectionKeyCache collectionKeyCache = CollectionKeyCacheImpl.getInstance(); + /** + * Initialise the service token store. + * + * @param zebedeePath the zebedee base directory (i.e. `$zebedee_root/zebedee`) + * @throws IOException If a filesystem error occurs. + */ + private void initServiceTokenStore(Path zebedeePath) throws IOException { + Path servicePath = createDir(zebedeePath, SERVICES); - this.schedulerKeyCache = collectionKeyCache; + this.serviceStore = new ServiceStoreImpl(servicePath); - CollectionKeyringImpl.init(collectionKeyCache, permissionsService, collections); - this.collectionKeyring = CollectionKeyringImpl.getInstance(); + info().data("services_path", servicePath.toString()) + .log("service token store initialised"); } /** * Initalise the CMS's Slack integration. If the required configuration values are not available the CMS will * default to No Op implementation - slack messages will be logged but sent to the Slack API. + * + * @param slackToken the slack token to use to authenticate requests to slack + * @param slackChannelsToNotfiyOnStartUp the list of slack channels in which to post startup notifications + * @param slackSupportChannelID the support slack channel id to include in messages so that user's know + * which channel to raise support requests */ - private void initSlackIntegration() { - String slackToken = System.getenv("slack_api_token"); - List startUpNotificationRecipients = slackChannelsToNotfiyOnStartUp(); + private void initSlackIntegration(String slackToken, List slackChannelsToNotfiyOnStartUp, String slackSupportChannelID) { boolean validConfig = true; if (isEmpty(slackToken)) { @@ -288,7 +539,7 @@ private void initSlackIntegration() { validConfig = false; } - if (startUpNotificationRecipients == null || startUpNotificationRecipients.isEmpty()) { + if (slackChannelsToNotfiyOnStartUp == null || slackChannelsToNotfiyOnStartUp.isEmpty()) { warn().log("env var START_UP_NOTIFY_LIST is null or empty"); validConfig = false; } @@ -296,156 +547,35 @@ private void initSlackIntegration() { if (validConfig) { info().log("valid Slack configuation found for CMS/Slack integration"); - this.slackClient = new SlackClientImpl(new Profile.Builder() + SlackClient slackClient = new SlackClientImpl(new Profile.Builder() .emoji(":flo:") .username("Florence") .authToken(slackToken) .create()); - this.slackNotifier = new SlackNotifier(this.slackClient); + this.slackNotifier = new SlackNotifier(slackClient); this.startUpNotifier = new SlackStartUpNotifier( slackClient, - startUpNotificationRecipients, - getSlackSupportChannelID() + slackChannelsToNotfiyOnStartUp, + slackSupportChannelID ); + info().data("slack_channels_to_notify_on_startup", slackChannelsToNotfiyOnStartUp.toString()) + .log("slack integration initialised"); + } else { warn().log("slack configuration missing/empty defaulting to No op implementation"); - this.slackClient = new NopSlackClientImpl(); this.slackNotifier = new NopNotifierImpl(); this.startUpNotifier = new NopStartUpNotifier(); } } - public boolean isUseVerificationAgent() { - return useVerificationAgent; - } - - public Path getZebedeePath() { - return zebedeePath; - } - - public Path getPublishedContentPath() { - return publishedContentPath; - } - - public Path getPublishedCollectionsPath() { - return publishedCollectionsPath; - } - - public Path getCollectionsPath() { - return collectionsPath; - } - - public Path getUsersPath() { - return usersPath; - } - - public Path getSessionsPath() { - return sessionsPath; - } - - public Path getPermissionsPath() { - return permissionsPath; - } - - public Path getTeamsPath() { - return teamsPath; - } - - public Path getRedirectPath() { - return redirectPath; - } - - public Path getKeyRingPath() { - return keyRingPath; - } - - public Path getServicePath() { - return servicePath; - } - - public Content getPublished() { - return this.published; - } - - private Content createPublished() { - Content content = new Content(publishedContentPath); - Path redirectPath = publishedContentPath.resolve(Content.REDIRECT); - if (!Files.exists(redirectPath)) { - content.setRedirects(new RedirectTablePartialMatch(content)); - try { - Files.createFile(redirectPath); - } catch (IOException e) { - error().data("requestedPath", redirectPath.toString()) - .logException(e, "could not save redirect to requested path"); - } - } else { - content.setRedirects(new RedirectTablePartialMatch(content, redirectPath)); + private void initVerificationAgent(PublishedCollections publishedCollections, String verificationUrl) { + if (isVerificationEnabled()) { + this.verificationAgent = new VerificationAgent(publishedCollections, verificationUrl); } - return content; - } - - public DataIndex getDataIndex() { - return this.dataIndex; - } - - public Collections getCollections() { - return this.collections; - } - - public PublishedCollections getPublishCollections() { - return this.publishedCollections; - } - - public Sessions getSessions() { - return this.sessions; - } - - public PermissionsService getPermissionsService() { - return this.permissionsService; - } - - public TeamsService getTeamsService() { - return this.teamsService; - } - - public UsersService getUsersService() { - return this.usersService; - } - - public VerificationAgent getVerificationAgent(boolean verificationIsEnabled, Zebedee z) { - return isUseVerificationAgent() && verificationIsEnabled ? new VerificationAgent(z) : null; - } - - public DatasetService getDatasetService() { - return datasetService; - } - - public ImageService getImageService() { - return imageService; - } - - public KafkaService getKafkaService() { - return kafkaService; - } - - public ServiceStoreImpl getServiceStore() { - return new ServiceStoreImpl(servicePath); - } - - public CollectionKeyring getCollectionKeyring() { - return this.collectionKeyring; - } - - public EncryptionKeyFactory getEncryptionKeyFactory() { - return this.encryptionKeyFactory; - } - - public CollectionKeyCache getSchedulerKeyringCache() { - return this.schedulerKeyCache; } private Path createDir(Path root, String dirName) throws IOException { @@ -456,12 +586,4 @@ private Path createDir(Path root, String dirName) throws IOException { } return dir; } - - public StartUpNotifier getStartUpNotifier() { - return startUpNotifier; - } - - public Notifier getSlackNotifier() { - return slackNotifier; - } } diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/DeletedContent.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/DeletedContent.java index 93c9a8b10..efe056f0d 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/DeletedContent.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/DeletedContent.java @@ -27,7 +27,8 @@ public class DeletedContent { private static ZebedeeCmsService zebedeeCmsService = ZebedeeCmsService.getInstance(); - private static DeletedContentService deletedContentService = DeletedContentServiceFactory.createInstance(); + private static DeletedContentService deletedContentService = DeletedContentServiceFactory.createInstance( + zebedeeCmsService.getZebedee().getPath()); /** * Get a list of recently deleted content. diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Identity.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Identity.java index e118af72a..5b4e679cf 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Identity.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Identity.java @@ -6,9 +6,9 @@ import com.github.onsdigital.zebedee.authorisation.UserIdentity; import com.github.onsdigital.zebedee.authorisation.UserIdentityException; import com.github.onsdigital.zebedee.json.response.Error; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.reader.util.RequestUtils; -import com.github.onsdigital.zebedee.service.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import org.apache.commons.lang3.StringUtils; import javax.servlet.http.HttpServletRequest; @@ -18,9 +18,9 @@ import static com.github.onsdigital.zebedee.logging.CMSLogEvent.error; import static com.github.onsdigital.zebedee.logging.CMSLogEvent.warn; -import static com.github.onsdigital.zebedee.service.ServiceTokenUtils.extractServiceAccountTokenFromAuthHeader; -import static com.github.onsdigital.zebedee.service.ServiceTokenUtils.isValidServiceAuthorizationHeader; -import static com.github.onsdigital.zebedee.service.ServiceTokenUtils.isValidServiceToken; +import static com.github.onsdigital.zebedee.servicetokens.ServiceTokenUtils.extractServiceAccountTokenFromAuthHeader; +import static com.github.onsdigital.zebedee.servicetokens.ServiceTokenUtils.isValidServiceAuthorizationHeader; +import static com.github.onsdigital.zebedee.servicetokens.ServiceTokenUtils.isValidServiceToken; import static com.github.onsdigital.zebedee.util.JsonUtils.writeResponseEntity; import static org.apache.http.HttpStatus.SC_OK; import static org.apache.http.HttpStatus.SC_UNAUTHORIZED; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Service.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Service.java index 238975be2..4a33b40b1 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Service.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/api/Service.java @@ -3,10 +3,10 @@ import com.github.davidcarboni.cryptolite.Random; import com.github.davidcarboni.restolino.framework.Api; import com.github.onsdigital.zebedee.json.response.Error; -import com.github.onsdigital.zebedee.model.ServiceAccount; -import com.github.onsdigital.zebedee.model.ServiceAccountWithToken; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccountWithToken; import com.github.onsdigital.zebedee.permissions.service.PermissionsService; -import com.github.onsdigital.zebedee.service.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import com.github.onsdigital.zebedee.session.model.Session; import com.github.onsdigital.zebedee.session.service.Sessions; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/CMSFeatureFlags.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/CMSFeatureFlags.java index 87c71f907..3cdb95c4c 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/CMSFeatureFlags.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/CMSFeatureFlags.java @@ -30,8 +30,6 @@ public class CMSFeatureFlags { private final boolean isDatasetVersionVerificationEnabled; - private final boolean isSessionAPIEnabled; - private final boolean isCentralisedKeyringEnabled; private final boolean isImagePublishingEnabled; @@ -47,7 +45,6 @@ private CMSFeatureFlags() { this.isDatasetImportEnabled = Boolean.valueOf(getConfigValue(ENABLE_DATASET_IMPORT)); this.isVerifyPublishEnabled = Boolean.valueOf(getConfigValue(ENABLE_VERIFY_PUBLISH_CONTENT)); this.isDatasetVersionVerificationEnabled = Boolean.valueOf(getConfigValue(ENABLE_DATASET_VERSION_VERIFICATION)); - this.isSessionAPIEnabled = Boolean.valueOf(getConfigValue(ENABLE_SESSIONS_API)); this.isCentralisedKeyringEnabled = Boolean.valueOf(getConfigValue(ENABLE_CENTRALISED_KEYRING)); this.isImagePublishingEnabled = Boolean.valueOf(getConfigValue(ENABLE_IMAGE_PUBLISHING)); this.isJwtSessionsEnabled = Boolean.valueOf(getConfigValue(ENABLE_JWT_SESSIONS)); @@ -56,7 +53,6 @@ private CMSFeatureFlags() { info().data(ENABLE_DATASET_IMPORT, isDatasetImportEnabled) .data(ENABLE_VERIFY_PUBLISH_CONTENT, isVerifyPublishEnabled) .data(ENABLE_DATASET_VERSION_VERIFICATION, isDatasetVersionVerificationEnabled) - .data(ENABLE_SESSIONS_API, isSessionAPIEnabled) .data(ENABLE_CENTRALISED_KEYRING, isCentralisedKeyringEnabled) .data(ENABLE_IMAGE_PUBLISHING, isImagePublishingEnabled) .data(ENABLE_JWT_SESSIONS, isJwtSessionsEnabled) @@ -88,10 +84,6 @@ public boolean isDatasetVersionVerificationEnabled() { return this.isDatasetVersionVerificationEnabled; } - public boolean isSessionAPIEnabled() { - return this.isSessionAPIEnabled; - } - public boolean isCentralisedKeyringEnabled() { return isCentralisedKeyringEnabled; } diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/Configuration.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/Configuration.java index 758363ca7..292826623 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/Configuration.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/configuration/Configuration.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.stream.Collectors; +import static com.github.onsdigital.zebedee.configuration.CMSFeatureFlags.cmsFeatureFlags; import static java.text.MessageFormat.format; import static org.apache.commons.lang.StringUtils.defaultIfBlank; @@ -107,6 +108,10 @@ public static String getSlackUsername() { return StringUtils.defaultIfBlank(getValue("SLACK_USERNAME"), DEFAULT_SLACK_USERNAME); } + public static String getSlackToken() { + return getValue("slack_api_token"); + } + public static List slackChannelsToNotfiyOnStartUp() { String val = getValue("START_UP_NOTIFY_LIST"); if (StringUtils.isEmpty(val)) { @@ -272,6 +277,10 @@ public static IvParameterSpec getKeyringInitVector() { * Get a map of cognito id and signing key pairs */ public static Map getCognitoKeyIdPairs() { + if (!cmsFeatureFlags().isJwtSessionsEnabled()) { + return new HashMap<>(); + } + String awsCognitoSigningKeyOne = getValue("AWS_COGNITO_SIGNING_KEY_ONE"); if (StringUtils.isEmpty(awsCognitoSigningKeyOne)) { throw new RuntimeException("expected public signing key one in environment variable but was empty"); diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/logging/CMSLogEvent.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/logging/CMSLogEvent.java index af6dd8f73..f2d42996b 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/logging/CMSLogEvent.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/logging/CMSLogEvent.java @@ -6,7 +6,7 @@ import com.github.onsdigital.zebedee.json.CollectionDescription; import com.github.onsdigital.zebedee.model.ClickEvent; import com.github.onsdigital.zebedee.model.Collection; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.permissions.cmd.CRUD; import com.github.onsdigital.zebedee.session.model.Session; import org.apache.commons.lang3.StringUtils; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/Content.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/Content.java index b3c3c6579..e843f2a84 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/Content.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/Content.java @@ -45,7 +45,6 @@ public class Content { private final Path dataVisualisationsPath; private RedirectTablePartialMatch redirects = null; - private Path publishedContentPath; public Content(Path path) { this.path = path; @@ -60,16 +59,7 @@ public Content(Path path) { } } - /** - * Create a new instance using an injected publishedContentPath. - * - * @param path - * @param publishedContentPath - */ - public Content(Path path, Path publishedContentPath) { - this(path); - this.publishedContentPath = publishedContentPath; - } + private static boolean isTimeseries(Path path) { return findByCriteria(path, p -> { @@ -239,64 +229,6 @@ public List uris(String glob) throws IOException { return uris; } - /** - * Returns a list of details with the details of child page details nested. - * - * @return - * @throws IOException - */ - public ContentDetail nestedDetails() throws IOException { - return nestedDetails(path); - } - - private ContentDetail nestedDetails(Path contentPath) throws IOException { - ContentDetail detail = details(contentPath.resolve("data.json")); - - // if the folder is empty put in an empty node with just a name. - if (detail == null) { - detail = new ContentDetail(); - detail.description = new ContentDetailDescription(contentPath.getFileName().toString()); - detail.uri = ""; - } - - detail.contentPath = "/" + getPublishedContentPath().relativize(contentPath); - detail.children = new ArrayList<>(); - - // todo: remove timeseries filter once we are caching the browse tree. - try (DirectoryStream stream = Files.newDirectoryStream(contentPath)) { - for (Path entry : stream) { - if (isVisible(entry)) { - ContentDetail child = nestedDetails(entry); - if (child != null) { - detail.children.add(child); - } - } - } - } - - try { - if (detail.children.size() > 1) { - java.util.Collections.sort(detail.children, (o1, o2) -> { - - if ((o1.description == null || o1.description.title == null) && (o2.description == null || o2.description.title == null)) { - return 0; // if both are null - } - if (o1.description == null || o1.description.title == null) { - return 1;//nulls last - } - if (o2.description == null || o2.description.title == null) { - return -1; - } - return o1.description.title.compareTo(o2.description.title); - }); - } - } catch (IllegalArgumentException e) { - error().data("path", contentPath.toString()).logException(e, "Failed to sort content detail items"); - } - - return detail; - } - /** * Returns an individual {@link ContentDetail} object for the given uri. * This method only ever reads published content so assumes no decryption is required. @@ -484,14 +416,6 @@ private static boolean isDataVisSubDir(Path path) { && !DATA_VIS_DIR.equals(path.getParent().getFileName().toString().toLowerCase()); } - private Path getPublishedContentPath() { - - if (publishedContentPath == null) - publishedContentPath = ZebedeeCmsService.getInstance().getZebedee().getPublishedContentPath(); - - return publishedContentPath; - } - public static boolean isDataVisualisationFile(Path path) { return findByCriteria(path, IS_DATA_VIZ_FILE); } diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/PublishedContent.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/PublishedContent.java new file mode 100644 index 000000000..96bbea8e7 --- /dev/null +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/PublishedContent.java @@ -0,0 +1,84 @@ +package com.github.onsdigital.zebedee.model; + +import com.github.onsdigital.zebedee.json.ContentDetail; +import com.github.onsdigital.zebedee.json.ContentDetailDescription; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; + +import static com.github.onsdigital.logging.v2.event.SimpleEvent.error; + +public class PublishedContent extends Content { + private Path publishedContentPath; + + /** + * Create a new instance using an injected publishedContentPath. + * + * @param publishedContentPath + */ + public PublishedContent(Path publishedContentPath) { + super(publishedContentPath); + this.publishedContentPath = publishedContentPath; + } + + /** + * Returns a list of details with the details of child page details nested. + * + * @return + * @throws IOException + */ + public ContentDetail nestedDetails() throws IOException { + return nestedDetails(getPath()); + } + + private ContentDetail nestedDetails(Path contentPath) throws IOException { + ContentDetail detail = details(contentPath.resolve("data.json")); + + // if the folder is empty put in an empty node with just a name. + if (detail == null) { + detail = new ContentDetail(); + detail.description = new ContentDetailDescription(contentPath.getFileName().toString()); + detail.uri = ""; + } + + detail.contentPath = "/" + getPath().relativize(contentPath); + detail.children = new ArrayList<>(); + + // todo: remove timeseries filter once we are caching the browse tree. + try (DirectoryStream stream = Files.newDirectoryStream(contentPath)) { + for (Path entry : stream) { + if (isVisible(entry)) { + ContentDetail child = nestedDetails(entry); + if (child != null) { + detail.children.add(child); + } + } + } + } + + try { + if (detail.children.size() > 1) { + java.util.Collections.sort(detail.children, (o1, o2) -> { + + if ((o1.description == null || o1.description.title == null) && (o2.description == null || o2.description.title == null)) { + return 0; // if both are null + } + if (o1.description == null || o1.description.title == null) { + return 1;//nulls last + } + if (o2.description == null || o2.description.title == null) { + return -1; + } + return o1.description.title.compareTo(o2.description.title); + }); + } + } catch (IllegalArgumentException e) { + error().data("path", contentPath.toString()).logException(e, "Failed to sort content detail items"); + } + + return detail; + } +} diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/RedirectTablePartialMatch.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/RedirectTablePartialMatch.java index 808c225b1..4fa97a8e0 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/RedirectTablePartialMatch.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/RedirectTablePartialMatch.java @@ -22,10 +22,6 @@ public RedirectTablePartialMatch(Content content) { this.content = content; } - public RedirectTablePartialMatch(Content content, Path path) { - this.content = content; - } - @Override public String get(String uri) { if (content.exists(uri, false)) { return uri; } // most times the URI will exist diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/publishing/PostPublisher.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/publishing/PostPublisher.java index cddb02339..c65dff870 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/publishing/PostPublisher.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/publishing/PostPublisher.java @@ -91,7 +91,7 @@ public static boolean postPublish(Zebedee zebedee, Collection collection, boolea ContentReader contentReader = new FileSystemContentReader(zebedee.getPublished().getPath()); ContentWriter contentWriter = new ContentWriter(zebedee.getPublished().getPath()); - applyDeletesToPublishing(collection, contentReader, contentWriter); + applyDeletesToPublishing(collection, contentReader, contentWriter, zebedee.getPath()); processManifestForMaster(collection, contentReader, contentWriter); copyFilesToMaster(zebedee, collection, collectionReader); @@ -132,10 +132,11 @@ private static Session getPublisherClassSession() { return zebdeePublisherSession; } - private static void applyDeletesToPublishing(Collection collection, ContentReader contentReader, ContentWriter contentWriter) { + private static void applyDeletesToPublishing(Collection collection, ContentReader contentReader, + ContentWriter contentWriter, Path zebedeePath) { try { - archiveContentToBeDeleted(collection, contentReader); + archiveContentToBeDeleted(collection, contentReader, zebedeePath); applyManifestDeletesToMaster(collection, contentReader, contentWriter); } catch (Exception e) { error().collectionID(collection) @@ -179,7 +180,7 @@ public static PublishedCollection getPublishedCollection(Collection collection) return publishedCollection; } - private static void archiveContentToBeDeleted(Collection collection, ContentReader contentReader) { + private static void archiveContentToBeDeleted(Collection collection, ContentReader contentReader, Path zebedeePath) { List pendingDeletes = collection.getDescription().getPendingDeletes(); @@ -195,7 +196,8 @@ private static void archiveContentToBeDeleted(Collection collection, ContentRead try { Page page = ContentUtil.deserialiseContent(contentReader.getResource(pendingDelete.getRoot().uri + "/data.json").getData()); - getDeletedContentService().storeDeletedContent(page, new Date(), urisToDelete, contentReader, collection); + getDeletedContentService(zebedeePath) + .storeDeletedContent(page, new Date(), urisToDelete, contentReader, collection); } catch (ZebedeeException | IOException e) { error().logException(e, "Failed to stored deleted content for URI: " + pendingDelete.getRoot().uri); } @@ -438,10 +440,10 @@ public static Path moveCollectionToArchive(Zebedee zebedee, Collection collectio return collectionJsonDestination; } - public synchronized static DeletedContentService getDeletedContentService() { + public static synchronized DeletedContentService getDeletedContentService(Path zebedeePath) { if (deletedContentService == null) - deletedContentService = DeletedContentServiceFactory.createInstance(); + deletedContentService = DeletedContentServiceFactory.createInstance(zebedeePath); return deletedContentService; } diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImpl.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImpl.java index d55d016ad..3732a9eb6 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImpl.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImpl.java @@ -3,9 +3,9 @@ import com.github.onsdigital.zebedee.api.Root; import com.github.onsdigital.zebedee.model.Collection; import com.github.onsdigital.zebedee.model.Collections; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.permissions.service.PermissionsService; -import com.github.onsdigital.zebedee.service.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import com.github.onsdigital.zebedee.session.model.Session; import com.github.onsdigital.zebedee.session.service.Sessions; import org.apache.commons.lang3.StringUtils; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CRUD.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CRUD.java index 0133a3d76..be5e3ddac 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CRUD.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/permissions/cmd/CRUD.java @@ -1,6 +1,6 @@ package com.github.onsdigital.zebedee.permissions.cmd; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import org.apache.commons.lang3.builder.HashCodeBuilder; import java.util.HashSet; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/DeletedContent/DeletedContentServiceFactory.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/DeletedContent/DeletedContentServiceFactory.java index fb62b0e29..0e701a2ef 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/DeletedContent/DeletedContentServiceFactory.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/DeletedContent/DeletedContentServiceFactory.java @@ -5,19 +5,21 @@ import com.github.onsdigital.zebedee.persistence.dao.impl.DeletedContentEventDaoImpl; import com.github.onsdigital.zebedee.persistence.dao.impl.DeletedContentFileStoreImpl; +import java.nio.file.Path; + public class DeletedContentServiceFactory { /** * Creates instances of DeletedContentService, handling feature switches and integration with zebedee. * @return */ - public static DeletedContentService createInstance() { + public static DeletedContentService createInstance(Path zebedeePath) { DeletedContentService deletedContentService; if (Configuration.isAuditDatabaseEnabled() && Configuration.storeDeletedContent()) { deletedContentService = new DeletedContentServiceImpl( new DeletedContentEventDaoImpl(), - new DeletedContentFileStoreImpl(Root.zebedee.getPath())); + new DeletedContentFileStoreImpl(zebedeePath)); } else { deletedContentService = new DeletedContentServiceStub(); } diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceTokenUtils.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/ServiceTokenUtils.java similarity index 95% rename from zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceTokenUtils.java rename to zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/ServiceTokenUtils.java index 97b244fe5..c8f538874 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceTokenUtils.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/ServiceTokenUtils.java @@ -1,15 +1,15 @@ -package com.github.onsdigital.zebedee.service; +package com.github.onsdigital.zebedee.servicetokens; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import org.apache.commons.lang3.StringUtils; import java.nio.file.Path; import java.util.regex.Pattern; -import static com.github.onsdigital.logging.v2.event.SimpleEvent.info; import static com.github.onsdigital.zebedee.logging.CMSLogEvent.warn; /** - * Utility class for {@link com.github.onsdigital.zebedee.model.ServiceAccount} token values. + * Utility class for {@link ServiceAccount} token values. */ public class ServiceTokenUtils { diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/ServiceAccount.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/model/ServiceAccount.java similarity index 75% rename from zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/ServiceAccount.java rename to zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/model/ServiceAccount.java index 24f3e0e36..7b4c7e61a 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/ServiceAccount.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/model/ServiceAccount.java @@ -1,4 +1,4 @@ -package com.github.onsdigital.zebedee.model; +package com.github.onsdigital.zebedee.servicetokens.model; public class ServiceAccount { diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/ServiceAccountWithToken.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/model/ServiceAccountWithToken.java similarity index 90% rename from zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/ServiceAccountWithToken.java rename to zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/model/ServiceAccountWithToken.java index d42cf9e87..cb35abb6e 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/ServiceAccountWithToken.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/model/ServiceAccountWithToken.java @@ -1,4 +1,4 @@ -package com.github.onsdigital.zebedee.model; +package com.github.onsdigital.zebedee.servicetokens.model; import com.github.onsdigital.zebedee.content.util.ContentUtil; import com.github.onsdigital.zebedee.json.JSONable; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceStore.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStore.java similarity index 87% rename from zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceStore.java rename to zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStore.java index 16cd55cf8..b02c55dba 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceStore.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStore.java @@ -1,6 +1,6 @@ -package com.github.onsdigital.zebedee.service; +package com.github.onsdigital.zebedee.servicetokens.store; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import java.io.IOException; import java.io.InputStream; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceStoreImpl.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStoreImpl.java similarity index 94% rename from zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceStoreImpl.java rename to zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStoreImpl.java index ebbf749c3..dff8d1da1 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/service/ServiceStoreImpl.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStoreImpl.java @@ -1,6 +1,7 @@ -package com.github.onsdigital.zebedee.service; +package com.github.onsdigital.zebedee.servicetokens.store; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.ServiceTokenUtils; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.util.serialiser.JSONSerialiser; import java.io.IOException; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/user/service/UsersServiceImpl.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/user/service/UsersServiceImpl.java index 9c8a1f36d..e50d9d3c4 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/user/service/UsersServiceImpl.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/user/service/UsersServiceImpl.java @@ -33,7 +33,6 @@ public class UsersServiceImpl implements UsersService { private static final Object MUTEX = new Object(); - private static final String JSON_EXT = ".json"; static final String SYSTEM_USER = "system"; private static UsersService INSTANCE = null; diff --git a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/verification/VerificationAgent.java b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/verification/VerificationAgent.java index e0699e269..1784b5907 100644 --- a/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/verification/VerificationAgent.java +++ b/zebedee-cms/src/main/java/com/github/onsdigital/zebedee/verification/VerificationAgent.java @@ -6,6 +6,7 @@ import com.github.onsdigital.zebedee.json.publishing.PublishedCollection; import com.github.onsdigital.zebedee.json.publishing.Result; import com.github.onsdigital.zebedee.json.publishing.UriInfo; +import com.github.onsdigital.zebedee.model.publishing.PublishedCollections; import com.github.onsdigital.zebedee.reader.CollectionReader; import com.github.onsdigital.zebedee.reader.Resource; import com.github.onsdigital.zebedee.util.DateConverter; @@ -37,18 +38,18 @@ */ public class VerificationAgent { + private final PublishedCollections publishedCollections; + private PooledHttpClient verificationProxyClient; private ExecutorService pool; - private Zebedee zebedee; - public VerificationAgent(Zebedee zebedee) { - this.zebedee = zebedee; - String defaultVerificationUrl = Configuration.getDefaultVerificationUrl(); - info().data("url", defaultVerificationUrl).log("Initializing verification agent"); + public VerificationAgent(PublishedCollections publishedCollections, String verificationUrl) { + this.publishedCollections = publishedCollections; + info().data("url", verificationUrl).log("Initializing verification agent"); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setMaxTotalConnection(100); clientConfiguration.setDisableRedirectHandling(true); - verificationProxyClient = new PooledHttpClient(defaultVerificationUrl, clientConfiguration); + verificationProxyClient = new PooledHttpClient(verificationUrl, clientConfiguration); pool = Executors.newFixedThreadPool(100); } @@ -172,7 +173,7 @@ private void setHash(UriInfo uriInfo, CollectionReader reader) { private void save(PublishedCollection publishedCollection, Path jsonPath) { try { - zebedee.getPublishedCollections().save(publishedCollection, jsonPath); + publishedCollections.save(publishedCollection, jsonPath); } catch (IOException e) { error().data("collectionId", publishedCollection.getId()) .logException(e, "Saving published collection failed"); diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/Builder.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/Builder.java index 52abbfa32..92647ea92 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/Builder.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/Builder.java @@ -121,7 +121,7 @@ public Builder() throws IOException, CollectionNotFoundException { teams = new ArrayList<>(); // Create some published content: - Path folder = zebedeeRootPath.resolve(Zebedee.PUBLISHED); + Path folder = zebedeeRootPath.resolve(ZebedeeConfiguration.PUBLISHED); contentUris = new ArrayList<>(); String contentUri; Path contentPath; @@ -141,7 +141,7 @@ public Builder() throws IOException, CollectionNotFoundException { contentUris.add(contentUri); // A couple of users: - Path users = zebedeeRootPath.resolve(Zebedee.USERS); + Path users = zebedeeRootPath.resolve(ZebedeeConfiguration.USERS); Files.createDirectories(users); administrator = clone(administratorTemplate); @@ -181,13 +181,13 @@ public Builder() throws IOException, CollectionNotFoundException { reviewer2Credentials = userCredentials(reviewer2); dataVisCredentials = userCredentials(dataVis); - Path sessions = zebedeeRootPath.resolve(Zebedee.SESSIONS); + Path sessions = zebedeeRootPath.resolve(ZebedeeConfiguration.SESSIONS); Files.createDirectories(sessions); // Set up some permissions: - Path permissions = zebedeeRootPath.resolve(Zebedee.PERMISSIONS); + Path permissions = zebedeeRootPath.resolve(ZebedeeConfiguration.PERMISSIONS); Files.createDirectories(permissions); - Path teams = zebedeeRootPath.resolve(Zebedee.TEAMS); + Path teams = zebedeeRootPath.resolve(ZebedeeConfiguration.TEAMS); Files.createDirectories(teams); AccessMapping accessMapping = new AccessMapping(); @@ -205,7 +205,6 @@ public Builder() throws IOException, CollectionNotFoundException { ZebedeeConfiguration configuration = new ZebedeeConfiguration(parent, false); - ReflectionTestUtils.setField(configuration,"slackClient",slackClient); this.zebedee = new Zebedee(configuration); inflationTeam = createTeam(reviewer1, teamNames[0], teams); @@ -229,22 +228,22 @@ public Builder() throws IOException, CollectionNotFoundException { public Builder(Path bootStrap) throws IOException, CollectionNotFoundException { this(); - FileUtils.deleteDirectory(this.zebedeeRootPath.resolve(Zebedee.PUBLISHED).toFile()); - FileUtils.deleteDirectory(this.zebedeeRootPath.resolve(Zebedee.LAUNCHPAD).toFile()); - FileUtils.deleteDirectory(this.zebedeeRootPath.resolve(Zebedee.COLLECTIONS).toFile()); - Files.createDirectory(this.zebedeeRootPath.resolve(Zebedee.PUBLISHED)); - Files.createDirectory(this.zebedeeRootPath.resolve(Zebedee.LAUNCHPAD)); - Files.createDirectory(this.zebedeeRootPath.resolve(Zebedee.COLLECTIONS)); + FileUtils.deleteDirectory(this.zebedeeRootPath.resolve(ZebedeeConfiguration.PUBLISHED).toFile()); + FileUtils.deleteDirectory(this.zebedeeRootPath.resolve(ZebedeeConfiguration.LAUNCHPAD).toFile()); + FileUtils.deleteDirectory(this.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS).toFile()); + Files.createDirectory(this.zebedeeRootPath.resolve(ZebedeeConfiguration.PUBLISHED)); + Files.createDirectory(this.zebedeeRootPath.resolve(ZebedeeConfiguration.LAUNCHPAD)); + Files.createDirectory(this.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS)); - FileUtils.copyDirectory(bootStrap.resolve(Zebedee.PUBLISHED).toFile(), this.zebedeeRootPath.resolve(Zebedee.PUBLISHED).toFile()); - if (Files.exists(bootStrap.resolve(Zebedee.LAUNCHPAD))) { - FileUtils.copyDirectory(bootStrap.resolve(Zebedee.LAUNCHPAD).toFile(), this.zebedeeRootPath.resolve(Zebedee.LAUNCHPAD).toFile()); + FileUtils.copyDirectory(bootStrap.resolve(ZebedeeConfiguration.PUBLISHED).toFile(), this.zebedeeRootPath.resolve(ZebedeeConfiguration.PUBLISHED).toFile()); + if (Files.exists(bootStrap.resolve(ZebedeeConfiguration.LAUNCHPAD))) { + FileUtils.copyDirectory(bootStrap.resolve(ZebedeeConfiguration.LAUNCHPAD).toFile(), this.zebedeeRootPath.resolve(ZebedeeConfiguration.LAUNCHPAD).toFile()); } else { - FileUtils.copyDirectory(bootStrap.resolve(Zebedee.PUBLISHED).toFile(), this.zebedeeRootPath.resolve(Zebedee.LAUNCHPAD).toFile()); // Not bothering with distinct launchpad + FileUtils.copyDirectory(bootStrap.resolve(ZebedeeConfiguration.PUBLISHED).toFile(), this.zebedeeRootPath.resolve(ZebedeeConfiguration.LAUNCHPAD).toFile()); // Not bothering with distinct launchpad } - if (Files.exists(bootStrap.resolve(Zebedee.COLLECTIONS))) { - FileUtils.copyDirectory(bootStrap.resolve(Zebedee.COLLECTIONS).toFile(), this.zebedeeRootPath.resolve(Zebedee.COLLECTIONS).toFile()); + if (Files.exists(bootStrap.resolve(ZebedeeConfiguration.COLLECTIONS))) { + FileUtils.copyDirectory(bootStrap.resolve(ZebedeeConfiguration.COLLECTIONS).toFile(), this.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS).toFile()); } } @@ -358,7 +357,7 @@ public void delete() throws IOException { */ public Path createPublishedFile(String uri) throws IOException { - Path published = zebedeeRootPath.resolve(Zebedee.PUBLISHED); + Path published = zebedeeRootPath.resolve(ZebedeeConfiguration.PUBLISHED); Path content = published.resolve(uri.substring(1)); Files.createDirectories(content.getParent()); Files.createFile(content); @@ -441,7 +440,7 @@ public Session createSession(String email) throws IOException { Path sessionPath; String sessionFileName = PathUtils.toFilename(session.getId()); sessionFileName += ".json"; - sessionPath = zebedeeRootPath.resolve(Zebedee.SESSIONS).resolve(sessionFileName); + sessionPath = zebedeeRootPath.resolve(ZebedeeConfiguration.SESSIONS).resolve(sessionFileName); // Serialise try (OutputStream output = Files.newOutputStream(sessionPath)) { @@ -462,7 +461,7 @@ public Session createSession(User user) throws IOException { Path sessionPath; String sessionFileName = PathUtils.toFilename(session.getId()); sessionFileName += ".json"; - sessionPath = zebedeeRootPath.resolve(Zebedee.SESSIONS).resolve(sessionFileName); + sessionPath = zebedeeRootPath.resolve(ZebedeeConfiguration.SESSIONS).resolve(sessionFileName); // Serialise try (OutputStream output = Files.newOutputStream(sessionPath)) { @@ -484,15 +483,15 @@ public Session createSession(User user) throws IOException { * @throws IOException If a filesystem error occurs. */ private Path createZebedee(Path parent) throws IOException { - Path path = Files.createDirectory(parent.resolve(Zebedee.ZEBEDEE)); - Files.createDirectory(path.resolve(Zebedee.PUBLISHED)); - Files.createDirectory(path.resolve(Zebedee.COLLECTIONS)); - Files.createDirectory(path.resolve(Zebedee.SESSIONS)); - Files.createDirectory(path.resolve(Zebedee.PERMISSIONS)); - Files.createDirectory(path.resolve(Zebedee.TEAMS)); - Files.createDirectory(path.resolve(Zebedee.LAUNCHPAD)); - Files.createDirectory(path.resolve(Zebedee.PUBLISHED_COLLECTIONS)); - Files.createDirectory(path.resolve(Zebedee.APPLICATION_KEYS)); + Path path = Files.createDirectory(parent.resolve(ZebedeeConfiguration.ZEBEDEE)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.PUBLISHED)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.COLLECTIONS)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.SESSIONS)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.PERMISSIONS)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.TEAMS)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.LAUNCHPAD)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.PUBLISHED_COLLECTIONS)); + Files.createDirectory(path.resolve(ZebedeeConfiguration.APPLICATION_KEYS)); return path; } @@ -511,7 +510,7 @@ private Path createZebedee(Path parent) throws IOException { private Path createCollection(String name, Path root) throws IOException { String filename = PathUtils.toFilename(name); - Path collections = root.resolve(Zebedee.COLLECTIONS); + Path collections = root.resolve(ZebedeeConfiguration.COLLECTIONS); // Create the folders: Path collection = collections.resolve(filename); diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/IdentityTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/IdentityTest.java index e1fd1ffae..0a898b66f 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/IdentityTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/IdentityTest.java @@ -5,8 +5,8 @@ import com.github.onsdigital.zebedee.authorisation.UserIdentityException; import com.github.onsdigital.zebedee.json.JSONable; import com.github.onsdigital.zebedee.json.response.Error; -import com.github.onsdigital.zebedee.model.ServiceAccount; -import com.github.onsdigital.zebedee.service.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import com.github.onsdigital.zebedee.session.model.Session; import org.junit.Before; import org.junit.Test; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/ServiceTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/ServiceTest.java index 35042fc4a..c042387a7 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/ServiceTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/api/ServiceTest.java @@ -2,9 +2,9 @@ import com.github.onsdigital.zebedee.exceptions.NotFoundException; import com.github.onsdigital.zebedee.exceptions.UnauthorizedException; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.permissions.service.PermissionsService; -import com.github.onsdigital.zebedee.service.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import com.github.onsdigital.zebedee.session.model.Session; import com.github.onsdigital.zebedee.session.service.Sessions; import org.junit.Before; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/authorisation/AuthorisationServiceImplTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/authorisation/AuthorisationServiceImplTest.java index fb4d1dc16..88d28497c 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/authorisation/AuthorisationServiceImplTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/authorisation/AuthorisationServiceImplTest.java @@ -2,8 +2,8 @@ import com.github.onsdigital.zebedee.json.CollectionDescription; import com.github.onsdigital.zebedee.model.Collection; -import com.github.onsdigital.zebedee.model.ServiceAccount; import com.github.onsdigital.zebedee.service.ServiceSupplier; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.session.model.Session; import com.github.onsdigital.zebedee.session.service.Sessions; import com.github.onsdigital.zebedee.user.service.UsersService; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/CollectionTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/CollectionTest.java index 936babb3e..e89f599ea 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/CollectionTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/CollectionTest.java @@ -3,7 +3,7 @@ import com.github.davidcarboni.cryptolite.Keys; import com.github.davidcarboni.cryptolite.Random; import com.github.davidcarboni.restolino.json.Serialiser; -import com.github.onsdigital.zebedee.Zebedee; +import com.github.onsdigital.zebedee.ZebedeeConfiguration; import com.github.onsdigital.zebedee.ZebedeeTestBaseFixture; import com.github.onsdigital.zebedee.content.page.base.PageDescription; import com.github.onsdigital.zebedee.content.page.base.PageType; @@ -132,7 +132,7 @@ public void shouldCreateCollection() throws Exception { // Then - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path releasePath = rootPath.resolve(filename); Path jsonPath = rootPath.resolve(filename + ".json"); @@ -176,7 +176,7 @@ public void shouldRenameCollection() throws Exception { Collection.rename(collectionDescription, newName, zebedee); // Then the collection is renamed. - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path releasePath = rootPath.resolve(filename); Path jsonPath = rootPath.resolve(filename + ".json"); @@ -219,7 +219,7 @@ public void shouldRenameCollectionSpecialChars() throws Exception { Collection.rename(collectionDescription, newName, zebedee); // Then the collection is renamed. - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path releasePath = rootPath.resolve(filename); Path jsonPath = rootPath.resolve(filename + ".json"); @@ -262,7 +262,7 @@ public void shouldRenameCollectionSameaName() throws Exception { Collection.rename(collectionDescription, newName, zebedee); // Then the collection is renamed. - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path releasePath = rootPath.resolve(filename); Path jsonPath = rootPath.resolve(filename + ".json"); @@ -320,7 +320,7 @@ public void shouldUpdateCollection() throws Exception { Collection.update(collection, updatedDescription, zebedee, new DummyScheduler(), publisher1Session); // Then the properties of the description passed to update have been updated. - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path collectionFolderPath = rootPath.resolve(filename); Path collectionJsonPath = rootPath.resolve(filename + ".json"); @@ -372,7 +372,7 @@ public void shouldRemoveViewerTeams() throws Exception { Collection.update(collection, updatedDescription, zebedee, new DummyScheduler(), publisher1Session); // Then the properties of the description passed to update have been updated. - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path collectionFolderPath = rootPath.resolve(filename); Path collectionJsonPath = rootPath.resolve(filename + ".json"); @@ -411,7 +411,7 @@ public void shouldUpdateCollectionNameIfCaseIsChanged() throws Exception { Collection.update(collection, updatedDescription, zebedee, new DummyScheduler(), publisher1Session); // Then the properties of the description passed to update have been updated. - Path rootPath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS); + Path rootPath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS); Path collectionFolderPath = rootPath.resolve(filename); Path collectionJsonPath = rootPath.resolve(filename + ".json"); @@ -480,7 +480,7 @@ public void shouldNotInstantiateInInvalidFolder() throws Exception { Collection.create(collectionDescription, zebedee, publisher1Session); - Path releasePath = builder.zebedeeRootPath.resolve(Zebedee.COLLECTIONS).resolve( + Path releasePath = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.COLLECTIONS).resolve( PathUtils.toFilename(name)); FileUtils.cleanDirectory(releasePath.toFile()); @@ -722,7 +722,7 @@ public void shouldEditPublished() throws IOException, BadRequestException { Path inProgress = builder.collections.get(1).resolve(Collection.IN_PROGRESS); assertTrue(Files.exists(inProgress.resolve(uri.substring(1)))); - Path published = builder.zebedeeRootPath.resolve(Zebedee.PUBLISHED); + Path published = builder.zebedeeRootPath.resolve(ZebedeeConfiguration.PUBLISHED); Path content = published.resolve(uri.substring(1)); assertTrue(Files.exists(content)); diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/ContentTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/ContentTest.java index 96bf192aa..db3fc42ce 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/ContentTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/ContentTest.java @@ -117,64 +117,6 @@ public void shouldGetDetailsForUri() throws IOException { assertEquals("/", result.uri); } - @Test - public void shouldGetNestedDetails() throws IOException { - - // Given an instance of content - Content content = new Content(basePath, basePath); - - // When the nestedDetails method is called - ContentDetail root = content.nestedDetails(); - - // Then the result has child nodes defined. - assertNotNull(root); - assertNotNull(root.children); - assertTrue(root.children.size() > 0); - assertEquals(baseContent.description.title, root.description.title); - } - - @Test - public void getNestedDetailsShouldAlphabeticallyOrderFiles() throws IOException { - - // Given an instance of content with three subdirectories - Content content = new Content(basePath, basePath); - - // When the nestedDetails method is called - ContentDetail root = content.nestedDetails(); - - // Then the result has child nodes ordered alphabetically - assertNotNull(root); - assertNotNull(root.children); - assertTrue(root.children.size() > 0); - assertEquals("Some sub 2015", root.children.get(0).description.title); - assertEquals(directoryBName, root.children.get(1).description.title); - assertEquals(directoryCName, root.children.get(2).description.title); - } - - - @Test - public void shouldGetNestedDetailsWithNoDataJsonFile() throws IOException { - - // Given an instance of content - Content content = new Content(basePath, basePath); - - // When the nestedDetails method is called - ContentDetail root = content.nestedDetails(); - - // Then a directory with no data.json file will still be evaluated but only the name returned without the URI. - ContentDetail bulletinDirectoryDetails = root.children.get(0).children.get(0); - - assertNotNull(bulletinDirectoryDetails); - assertEquals(bulletinsDirectoryName, bulletinDirectoryDetails.description.title); - assertTrue(bulletinDirectoryDetails.children.size() > 0); - - ContentDetail bulletinDetails = bulletinDirectoryDetails.children.get(0); - assertNotNull(bulletinDetails); - assertEquals(bulletinContent.description.title, bulletinDetails.description.title); - assertEquals("/" + basePath.relativize(exampleBulletinDirectory), bulletinDetails.uri); - assertTrue(bulletinDetails.children.size() == 0); - } - @Test public void listTimeSeriesDirectoriesShouldReturnListOfTimeseriesDirectories() throws IOException { diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/PublishedContentTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/PublishedContentTest.java new file mode 100644 index 000000000..dca6074f5 --- /dev/null +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/model/PublishedContentTest.java @@ -0,0 +1,161 @@ +package com.github.onsdigital.zebedee.model; + +import com.github.davidcarboni.restolino.json.Serialiser; +import com.github.onsdigital.zebedee.json.ContentDetail; +import com.github.onsdigital.zebedee.json.ContentDetailDescription; +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class PublishedContentTest { + + private String filename = "data.json"; + private String directoryAName = "subdira"; + private String directoryBName = "subdirb"; + private String directoryCName = "subdirc"; + private String bulletinsDirectoryName = "bulletins"; + private String timeseriesDirectoryName = "timeseries"; + private String exampleBulletinName = "gdppreliminaryestimateq32014"; + + private Path basePath; // base path for the working directory + private Path baseJsonFile; // path of the data.json file in the base directory (the home page) + private ContentDetail baseContent; // The object to serialise into the base directory data.json + + private Path subDirectoryJsonFile; // a json file for the sub directory + private ContentDetail subContent; // the object to serialise into the sub directory data.json + + private Path bulletinDirectory; + private Path exampleBulletinDirectory; + private Path timeseriesDirectory1; + private Path timeseriesDirectory2; + private Path exampleBulletinJsonFile; + private ContentDetail bulletinContent; + + @Before + public void setUp() throws Exception { + basePath = Files.createTempDirectory(this.getClass().getSimpleName()); + baseJsonFile = basePath.resolve(filename); + Path subDirectoryA = basePath.resolve(directoryAName); + Path subDirectoryB = basePath.resolve(directoryBName); + Path subDirectoryC = basePath.resolve(directoryCName); + subDirectoryJsonFile = subDirectoryA.resolve(filename); + Files.createFile(baseJsonFile); + + baseContent = new ContentDetail(); + baseContent.description = new ContentDetailDescription("Some release 2014"); + baseContent.type = "home"; + + // Serialise + try (OutputStream output = Files.newOutputStream(baseJsonFile)) { + Serialiser.serialise(output, baseContent); + } + + Files.createDirectory(subDirectoryC); + Files.createDirectory(subDirectoryA); + Files.createDirectory(subDirectoryB); + + subContent = new ContentDetail(); + subContent.description = new ContentDetailDescription("Some sub 2015"); + subContent.type = "t2"; + + // Serialise + try (OutputStream output = Files.newOutputStream(subDirectoryJsonFile)) { + Serialiser.serialise(output, subContent); + } + + + bulletinDirectory = subDirectoryA.resolve(bulletinsDirectoryName); + Files.createDirectory(bulletinDirectory); + exampleBulletinDirectory = bulletinDirectory.resolve(exampleBulletinName); + Files.createDirectory(exampleBulletinDirectory); + exampleBulletinJsonFile = exampleBulletinDirectory.resolve(filename); + + timeseriesDirectory1 = subDirectoryA.resolve(timeseriesDirectoryName); + Files.createDirectory(timeseriesDirectory1); + timeseriesDirectory2 = subDirectoryB.resolve(timeseriesDirectoryName); + Files.createDirectory(timeseriesDirectory2); + + bulletinContent = new ContentDetail(); + bulletinContent.description = new ContentDetailDescription("Some bulletin 2010"); + bulletinContent.type = "bulletin"; + + // Serialise + try (OutputStream output = Files.newOutputStream(exampleBulletinJsonFile)) { + Serialiser.serialise(output, bulletinContent); + } + } + + @After + public void tearDown() throws Exception { + FileUtils.deleteDirectory(basePath.toFile()); + } + + + @Test + public void shouldGetNestedDetails() throws IOException { + + // Given an instance of content + PublishedContent content = new PublishedContent(basePath); + + // When the nestedDetails method is called + ContentDetail root = content.nestedDetails(); + + // Then the result has child nodes defined. + assertNotNull(root); + assertNotNull(root.children); + assertTrue(root.children.size() > 0); + assertEquals(baseContent.description.title, root.description.title); + } + + @Test + public void getNestedDetailsShouldAlphabeticallyOrderFiles() throws IOException { + + // Given an instance of content with three subdirectories + PublishedContent content = new PublishedContent(basePath); + + // When the nestedDetails method is called + ContentDetail root = content.nestedDetails(); + + // Then the result has child nodes ordered alphabetically + assertNotNull(root); + assertNotNull(root.children); + assertTrue(root.children.size() > 0); + assertEquals("Some sub 2015", root.children.get(0).description.title); + assertEquals(directoryBName, root.children.get(1).description.title); + assertEquals(directoryCName, root.children.get(2).description.title); + } + + + @Test + public void shouldGetNestedDetailsWithNoDataJsonFile() throws IOException { + + // Given an instance of content + PublishedContent content = new PublishedContent(basePath); + + // When the nestedDetails method is called + ContentDetail root = content.nestedDetails(); + + // Then a directory with no data.json file will still be evaluated but only the name returned without the URI. + ContentDetail bulletinDirectoryDetails = root.children.get(0).children.get(0); + + assertNotNull(bulletinDirectoryDetails); + assertEquals(bulletinsDirectoryName, bulletinDirectoryDetails.description.title); + assertTrue(bulletinDirectoryDetails.children.size() > 0); + + ContentDetail bulletinDetails = bulletinDirectoryDetails.children.get(0); + assertNotNull(bulletinDetails); + assertEquals(bulletinContent.description.title, bulletinDetails.description.title); + assertEquals("/" + basePath.relativize(exampleBulletinDirectory), bulletinDetails.uri); + assertTrue(bulletinDetails.children.size() == 0); + } +} diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImplTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImplTest.java index e95add361..693d4567e 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImplTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/permissions/cmd/CMDPermissionsServiceImplTest.java @@ -4,9 +4,9 @@ import com.github.onsdigital.zebedee.json.CollectionDescription; import com.github.onsdigital.zebedee.model.Collection; import com.github.onsdigital.zebedee.model.Collections; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; import com.github.onsdigital.zebedee.permissions.service.PermissionsService; -import com.github.onsdigital.zebedee.service.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; import com.github.onsdigital.zebedee.session.model.Session; import com.github.onsdigital.zebedee.session.service.Sessions; import org.apache.http.HttpStatus; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/service/ServiceTokenUtilsTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/servicetokens/ServiceTokenUtilsTest.java similarity index 95% rename from zebedee-cms/src/test/java/com/github/onsdigital/zebedee/service/ServiceTokenUtilsTest.java rename to zebedee-cms/src/test/java/com/github/onsdigital/zebedee/servicetokens/ServiceTokenUtilsTest.java index 01af8ca5f..a0e035f32 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/service/ServiceTokenUtilsTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/servicetokens/ServiceTokenUtilsTest.java @@ -1,11 +1,12 @@ -package com.github.onsdigital.zebedee.service; +package com.github.onsdigital.zebedee.servicetokens; +import com.github.onsdigital.zebedee.servicetokens.ServiceTokenUtils; import org.junit.Test; import java.nio.file.Path; import java.nio.file.Paths; -import static com.github.onsdigital.zebedee.service.ServiceTokenUtils.BEARER_PREFIX_UC; +import static com.github.onsdigital.zebedee.servicetokens.ServiceTokenUtils.BEARER_PREFIX_UC; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/service/ServiceStoreImplTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStoreImplTest.java similarity index 95% rename from zebedee-cms/src/test/java/com/github/onsdigital/zebedee/service/ServiceStoreImplTest.java rename to zebedee-cms/src/test/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStoreImplTest.java index a99b78dfb..73782f22b 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/service/ServiceStoreImplTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/servicetokens/store/ServiceStoreImplTest.java @@ -1,6 +1,8 @@ -package com.github.onsdigital.zebedee.service; +package com.github.onsdigital.zebedee.servicetokens.store; -import com.github.onsdigital.zebedee.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.model.ServiceAccount; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStore; +import com.github.onsdigital.zebedee.servicetokens.store.ServiceStoreImpl; import com.github.onsdigital.zebedee.util.serialiser.JSONSerialiser; import org.junit.Before; import org.junit.Rule; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/session/service/SessionsServiceServiceImplTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/session/service/SessionsServiceServiceImplTest.java index 4372aba02..7be5f7cfb 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/session/service/SessionsServiceServiceImplTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/session/service/SessionsServiceServiceImplTest.java @@ -27,7 +27,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; -import static com.github.onsdigital.zebedee.Zebedee.SESSIONS; +import static com.github.onsdigital.zebedee.ZebedeeConfiguration.SESSIONS; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertNull; diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/teams/store/TeamsStoreFileSystemImplTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/teams/store/TeamsStoreFileSystemImplTest.java index 75ee54301..b5f732808 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/teams/store/TeamsStoreFileSystemImplTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/teams/store/TeamsStoreFileSystemImplTest.java @@ -1,6 +1,7 @@ package com.github.onsdigital.zebedee.teams.store; import com.github.davidcarboni.restolino.json.Serialiser; +import com.github.onsdigital.zebedee.ZebedeeConfiguration; import com.github.onsdigital.zebedee.exceptions.NotFoundException; import com.github.onsdigital.zebedee.teams.model.Team; import com.github.onsdigital.zebedee.teams.service.TeamsServiceImpl; @@ -28,7 +29,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; -import static com.github.onsdigital.zebedee.Zebedee.TEAMS; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -68,7 +68,7 @@ public void setup() throws Exception { zebedeeRoot = new TemporaryFolder(); zebedeeRoot.create(); zebedeeRoot.newFolder("teams"); - teamsPath = zebedeeRoot.getRoot().toPath().resolve(TEAMS); + teamsPath = zebedeeRoot.getRoot().toPath().resolve(ZebedeeConfiguration.TEAMS); store = new TeamsStoreFileSystemImpl(teamsPath); diff --git a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/user/service/UsersServiceTest.java b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/user/service/UsersServiceTest.java index c50669d51..913791a6e 100644 --- a/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/user/service/UsersServiceTest.java +++ b/zebedee-cms/src/test/java/com/github/onsdigital/zebedee/user/service/UsersServiceTest.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; -import java.util.function.Supplier; import static com.github.onsdigital.zebedee.user.service.UsersServiceImpl.SYSTEM_USER; import static org.hamcrest.CoreMatchers.equalTo; @@ -55,9 +54,6 @@ public class UsersServiceTest { private static final String KEY_IDENTIFIER = "Valar morghulis"; private static final String MOCK_USER_NAME = "A girl is no one"; - @Mock - private Collections collections; - @Mock private PermissionsService permissions; @@ -81,7 +77,6 @@ public class UsersServiceTest { private UsersService service; private User user; - private Supplier keyringSupplier; @Before public void setUp() throws Exception { @@ -504,9 +499,6 @@ public void setPasswod_success() throws Exception { .thenReturn(desc2); allCollections.add(c2); - when(collections.list()) - .thenReturn(allCollections); - boolean result = service.setPassword(session, credentials); assertTrue(result);