Skip to content

Commit

Permalink
Added policy
Browse files Browse the repository at this point in the history
  • Loading branch information
jorizci committed Aug 17, 2018
1 parent 479f596 commit 8efe2ee
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 1 deletion.
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 src/main/java/uk/ac/ebi/ega/accession/policy/model/Policy.java
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();

}
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> {
}
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> {

}
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;
}
}
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> {

}
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;
}
}
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> {

}
Loading

0 comments on commit 8efe2ee

Please sign in to comment.