-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
486 additions
and
1 deletion.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
src/main/java/uk/ac/ebi/ega/accession/configuration/PolicyServiceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package uk.ac.ebi.ega.accession.configuration; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import uk.ac.ebi.ampt2d.commons.accession.core.AccessioningService; | ||
import uk.ac.ebi.ampt2d.commons.accession.core.BasicAccessioningService; | ||
import uk.ac.ebi.ampt2d.commons.accession.core.DatabaseService; | ||
import uk.ac.ebi.ampt2d.commons.accession.core.DecoratedAccessioningService; | ||
import uk.ac.ebi.ampt2d.commons.accession.generators.monotonic.MonotonicAccessionGenerator; | ||
import uk.ac.ebi.ampt2d.commons.accession.generators.monotonic.MonotonicRange; | ||
import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.ContiguousIdBlockService; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.MonotonicDatabaseService; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.service.BasicJpaInactiveAccessionService; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicSpringDataRepositoryDatabaseService; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.services.InactiveAccessionService; | ||
import uk.ac.ebi.ega.accession.policy.model.Policy; | ||
import uk.ac.ebi.ega.accession.policy.persistence.HistoricLogPolicyEntity; | ||
import uk.ac.ebi.ega.accession.policy.persistence.HistoricLogPolicyRepository; | ||
import uk.ac.ebi.ega.accession.policy.persistence.HistoricPolicyEntity; | ||
import uk.ac.ebi.ega.accession.policy.persistence.HistoricPolicyRepository; | ||
import uk.ac.ebi.ega.accession.policy.persistence.PolicyEntity; | ||
import uk.ac.ebi.ega.accession.policy.persistence.PolicyEntityRepository; | ||
|
||
import java.util.Collection; | ||
|
||
@Configuration | ||
@EntityScan({"uk.ac.ebi.ega.accession.policy.persistence"}) | ||
@EnableJpaRepositories(basePackages = {"uk.ac.ebi.ega.accession.policy.persistence"}) | ||
public class PolicyServiceConfiguration { | ||
|
||
private final String PAD_FORMAT = "%011d"; | ||
|
||
private final String PREFIX = "EGAP"; | ||
|
||
private final String CATEGORY_ID = "policy"; | ||
|
||
@Autowired | ||
private ContiguousIdBlockService blockService; | ||
|
||
@Autowired | ||
private PolicyEntityRepository repository; | ||
|
||
@Autowired | ||
private HistoricPolicyRepository historicRepository; | ||
|
||
@Autowired | ||
private HistoricLogPolicyRepository historicLogRepository; | ||
|
||
@Bean | ||
public AccessioningService<Policy, String, String> prefixPolicyAccessionService() { | ||
return DecoratedAccessioningService.buildPrefixPaddedLongAccessionService(policyAccessionService(), PREFIX, | ||
PAD_FORMAT, Long::parseLong); | ||
} | ||
|
||
@Bean | ||
public AccessioningService<Policy, String, Long> policyAccessionService() { | ||
return new BasicAccessioningService<>( | ||
new MonotonicAccessionGenerator<>(CATEGORY_ID, "ega-accession-01", blockService, | ||
monotonicDatabaseService()), | ||
policyAccessioningDatabaseService(), | ||
policy -> policy.getSubmissionAccount() + "_" + policy.getAlias(), | ||
new SHA1HashingFunction()); | ||
} | ||
|
||
public MonotonicDatabaseService monotonicDatabaseService() { | ||
return new MonotonicDatabaseService() { | ||
@Override | ||
public long[] getAccessionsInRanges(Collection<MonotonicRange> collection) { | ||
//Not implemented yet | ||
return new long[0]; | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
public DatabaseService<Policy, String, Long> policyAccessioningDatabaseService() { | ||
return new BasicSpringDataRepositoryDatabaseService<>(repository, | ||
PolicyEntity::new, | ||
historicPolicyAccessionService()); | ||
} | ||
|
||
@Bean | ||
public InactiveAccessionService<Policy, Long, PolicyEntity> historicPolicyAccessionService() { | ||
return new BasicJpaInactiveAccessionService<>( | ||
historicLogRepository, | ||
HistoricPolicyEntity::new, | ||
historicRepository, | ||
HistoricLogPolicyEntity::new); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/ac/ebi/ega/accession/policy/model/Policy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.model; | ||
|
||
public interface Policy { | ||
|
||
String getSubmissionAccount(); | ||
|
||
String getAlias(); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/ac/ebi/ega/accession/policy/persistence/HistoricLogPolicyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.persistence; | ||
|
||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.OperationEntity; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
public class HistoricLogPolicyEntity extends OperationEntity<Long> { | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/ac/ebi/ega/accession/policy/persistence/HistoricLogPolicyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.persistence; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IHistoryRepository; | ||
|
||
@Repository | ||
public interface HistoricLogPolicyRepository extends IHistoryRepository<Long, HistoricLogPolicyEntity, Long> { | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/uk/ac/ebi/ega/accession/policy/persistence/HistoricPolicyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.persistence; | ||
|
||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.InactiveAccessionEntity; | ||
import uk.ac.ebi.ega.accession.policy.model.Policy; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
public class HistoricPolicyEntity extends InactiveAccessionEntity<Policy, Long> implements Policy { | ||
|
||
@Column(nullable = false) | ||
private String submissionAccount; | ||
|
||
@Column(nullable = false) | ||
private String alias; | ||
|
||
HistoricPolicyEntity() { | ||
super(); | ||
} | ||
|
||
public HistoricPolicyEntity(PolicyEntity entity) { | ||
super(entity); | ||
this.submissionAccount = entity.getSubmissionAccount(); | ||
this.alias = entity.getAlias(); | ||
} | ||
|
||
@Override | ||
public Policy getModel() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getSubmissionAccount() { | ||
return submissionAccount; | ||
} | ||
|
||
@Override | ||
public String getAlias() { | ||
return alias; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/ac/ebi/ega/accession/policy/persistence/HistoricPolicyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.persistence; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.InactiveAccessionRepository; | ||
|
||
@Repository | ||
public interface HistoricPolicyRepository extends InactiveAccessionRepository<HistoricPolicyEntity> { | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/uk/ac/ebi/ega/accession/policy/persistence/PolicyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.persistence; | ||
|
||
import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.AccessionedEntity; | ||
import uk.ac.ebi.ega.accession.policy.model.Policy; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
public class PolicyEntity extends AccessionedEntity<Policy, Long> implements Policy { | ||
|
||
@Column(nullable = false) | ||
private String submissionAccount; | ||
|
||
@Column(nullable = false) | ||
private String alias; | ||
|
||
PolicyEntity() { | ||
super(null, null, -1); | ||
} | ||
|
||
public PolicyEntity(Policy policy, Long accession, String hashedMessage, int version) { | ||
super(hashedMessage, accession, version); | ||
this.submissionAccount = policy.getSubmissionAccount(); | ||
this.alias = policy.getAlias(); | ||
} | ||
|
||
public PolicyEntity(AccessionWrapper<Policy, String, Long> wrapper) { | ||
this(wrapper.getData(), wrapper.getAccession(), wrapper.getHash(), wrapper.getVersion()); | ||
} | ||
|
||
@Override | ||
public Policy getModel() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getSubmissionAccount() { | ||
return submissionAccount; | ||
} | ||
|
||
@Override | ||
public String getAlias() { | ||
return alias; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/ac/ebi/ega/accession/policy/persistence/PolicyEntityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* | ||
* Copyright 2018 EMBL - European Bioinformatics Institute | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package uk.ac.ebi.ega.accession.policy.persistence; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IAccessionedObjectRepository; | ||
|
||
@Repository | ||
public interface PolicyEntityRepository extends IAccessionedObjectRepository<PolicyEntity, Long> { | ||
|
||
} |
Oops, something went wrong.