Skip to content

Commit

Permalink
Merge pull request #122 from gdcc/force-repo-config
Browse files Browse the repository at this point in the history
Force repo config
  • Loading branch information
poikilotherm authored Jan 25, 2023
2 parents ff5b6b6 + f3cb25e commit 66d4213
Show file tree
Hide file tree
Showing 15 changed files with 615 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package io.gdcc.xoai.dataprovider.handlers;

import io.gdcc.xoai.dataprovider.exceptions.InternalOAIException;
import io.gdcc.xoai.dataprovider.exceptions.handler.HandlerException;
import io.gdcc.xoai.dataprovider.model.Context;
import io.gdcc.xoai.dataprovider.repository.Repository;
Expand All @@ -20,8 +19,6 @@
import io.gdcc.xoai.xml.XmlWritable;
import io.gdcc.xoai.xml.XmlWriter;
import io.gdcc.xoai.xmlio.exceptions.XmlWriteException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.slf4j.Logger;
Expand All @@ -35,42 +32,6 @@ public final class IdentifyHandler extends VerbHandler<Identify> {

public IdentifyHandler(Context context, Repository repository) {
super(context, repository);

// Static validation
RepositoryConfiguration configuration = getRepository().getConfiguration();
if (configuration == null)
throw new InternalOAIException("No repository configuration provided");
if (configuration.getMaxListSets() <= 0)
throw new InternalOAIException(
"The repository configuration must return maxListSets greater then 0");
if (configuration.getMaxListIdentifiers() <= 0)
throw new InternalOAIException(
"The repository configuration must return maxListIdentifiers greater then 0");
if (configuration.getMaxListRecords() <= 0)
throw new InternalOAIException(
"The repository configuration must return maxListRecords greater then 0");
if (configuration.getAdminEmails() == null || configuration.getAdminEmails().isEmpty())
throw new InternalOAIException(
"The repository configuration must return at least one admin email");
try {
if (configuration.getBaseUrl() == null)
throw new InternalOAIException(
"The repository configuration must return a valid base url (absolute)");
new URL(configuration.getBaseUrl());
} catch (MalformedURLException e) {
throw new InternalOAIException(
"The repository configuration must return a valid base url (absolute)", e);
}
if (configuration.getDeleteMethod() == null)
throw new InternalOAIException(
"The repository configuration must return a valid delete method");
if (configuration.getEarliestDate() == null)
throw new InternalOAIException(
"The repository configuration must return a valid earliest date. That's the"
+ " date of the first inserted item");
if (configuration.getRepositoryName() == null)
throw new InternalOAIException(
"The repository configuration must return a valid repository name");
}

@Override
Expand All @@ -79,7 +40,9 @@ public Identify handle(Request request) throws HandlerException {
RepositoryConfiguration configuration = getRepository().getConfiguration();
identify.withBaseURL(configuration.getBaseUrl());
identify.withRepositoryName(configuration.getRepositoryName());
for (String mail : configuration.getAdminEmails()) identify.getAdminEmails().add(mail);
for (String mail : configuration.getAdminEmails()) {
identify.getAdminEmails().add(mail);
}
identify.withEarliestDatestamp(configuration.getEarliestDate());
identify.withDeletedRecord(DeletedRecord.valueOf(configuration.getDeleteMethod().name()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@

package io.gdcc.xoai.dataprovider.repository;

import io.gdcc.xoai.dataprovider.exceptions.InternalOAIException;

public final class Repository {
public static Repository repository() {
return new Repository();

/* Do not let a repository get constructed without a configuration. Remember: this is crucial! */
private Repository() {}

public Repository(RepositoryConfiguration configuration) {
this.configuration = configuration;
}

private RepositoryConfiguration configuration = RepositoryConfiguration.defaults();
private RepositoryConfiguration configuration;
private ItemRepository itemRepository = null;
private SetRepository setRepository = null;

public RepositoryConfiguration getConfiguration() {
if (this.configuration == null) {
throw new InternalOAIException(
"Despite a private constructor this repository instance has no configuration");
}
return configuration;
}

public Repository withConfiguration(RepositoryConfiguration configuration) {
public Repository setConfiguration(RepositoryConfiguration configuration) {
this.configuration = configuration;
return this;
}
Expand Down
Loading

0 comments on commit 66d4213

Please sign in to comment.