Skip to content

Commit

Permalink
Added dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
jorizci committed Aug 17, 2018
1 parent 8efe2ee commit abf9e30
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.dataset.model.Dataset;
import uk.ac.ebi.ega.accession.dataset.persistence.HistoricLogDatasetEntity;
import uk.ac.ebi.ega.accession.dataset.persistence.HistoricLogDatasetRepository;
import uk.ac.ebi.ega.accession.dataset.persistence.HistoricDatasetEntity;
import uk.ac.ebi.ega.accession.dataset.persistence.HistoricDatasetRepository;
import uk.ac.ebi.ega.accession.dataset.persistence.DatasetEntity;
import uk.ac.ebi.ega.accession.dataset.persistence.DatasetEntityRepository;

import java.util.Collection;

@Configuration
@EntityScan({"uk.ac.ebi.ega.accession.dataset.persistence"})
@EnableJpaRepositories(basePackages = {"uk.ac.ebi.ega.accession.dataset.persistence"})
public class DatasetServiceConfiguration {

private final String PAD_FORMAT = "%011d";

private final String PREFIX = "EGAD";

private final String CATEGORY_ID = "dataset";

@Autowired
private ContiguousIdBlockService blockService;

@Autowired
private DatasetEntityRepository repository;

@Autowired
private HistoricDatasetRepository historicRepository;

@Autowired
private HistoricLogDatasetRepository historicLogRepository;

@Bean
public AccessioningService<Dataset, String, String> prefixDatasetAccessionService() {
return DecoratedAccessioningService.buildPrefixPaddedLongAccessionService(datasetAccessionService(), PREFIX,
PAD_FORMAT, Long::parseLong);
}

@Bean
public AccessioningService<Dataset, String, Long> datasetAccessionService() {
return new BasicAccessioningService<>(
new MonotonicAccessionGenerator<>(CATEGORY_ID, "ega-accession-01", blockService,
monotonicDatabaseService()),
datasetAccessioningDatabaseService(),
dataset -> dataset.getSubmissionAccount() + "_" + dataset.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<Dataset, String, Long> datasetAccessioningDatabaseService() {
return new BasicSpringDataRepositoryDatabaseService<>(repository,
DatasetEntity::new,
historicDatasetAccessionService());
}

@Bean
public InactiveAccessionService<Dataset, Long, DatasetEntity> historicDatasetAccessionService() {
return new BasicJpaInactiveAccessionService<>(
historicLogRepository,
HistoricDatasetEntity::new,
historicRepository,
HistoricLogDatasetEntity::new);
}

}
26 changes: 26 additions & 0 deletions src/main/java/uk/ac/ebi/ega/accession/dataset/model/Dataset.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.dataset.model;

public interface Dataset {

String getSubmissionAccount();

String getAlias();

}
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.dataset.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.dataset.model.Dataset;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class DatasetEntity extends AccessionedEntity<Dataset, Long> implements Dataset {

@Column(nullable = false)
private String submissionAccount;

@Column(nullable = false)
private String alias;

DatasetEntity() {
super(null, null, -1);
}

public DatasetEntity(Dataset dataset, Long accession, String hashedMessage, int version) {
super(hashedMessage, accession, version);
this.submissionAccount = dataset.getSubmissionAccount();
this.alias = dataset.getAlias();
}

public DatasetEntity(AccessionWrapper<Dataset, String, Long> wrapper) {
this(wrapper.getData(), wrapper.getAccession(), wrapper.getHash(), wrapper.getVersion());
}

@Override
public Dataset 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.dataset.persistence;

import org.springframework.stereotype.Repository;
import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IAccessionedObjectRepository;

@Repository
public interface DatasetEntityRepository extends IAccessionedObjectRepository<DatasetEntity, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* 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.dataset.persistence;

import org.springframework.transaction.PlatformTransactionManager;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.BasicJpaAccessionedObjectCustomRepositoryImpl;

import javax.persistence.EntityManager;

public class DatasetEntityRepositoryImpl extends BasicJpaAccessionedObjectCustomRepositoryImpl<Long, DatasetEntity> {

public DatasetEntityRepositoryImpl(PlatformTransactionManager platformTransactionManager, EntityManager entityManager) {
super(DatasetEntity.class, platformTransactionManager, entityManager);
}
}
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.dataset.persistence;

import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.InactiveAccessionEntity;
import uk.ac.ebi.ega.accession.dataset.model.Dataset;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class HistoricDatasetEntity extends InactiveAccessionEntity<Dataset, Long> implements Dataset {

@Column(nullable = false)
private String submissionAccount;

@Column(nullable = false)
private String alias;

HistoricDatasetEntity() {
super();
}

public HistoricDatasetEntity(DatasetEntity entity) {
super(entity);
this.submissionAccount = entity.getSubmissionAccount();
this.alias = entity.getAlias();
}

@Override
public Dataset 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.dataset.persistence;

import org.springframework.stereotype.Repository;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.InactiveAccessionRepository;

@Repository
public interface HistoricDatasetRepository extends InactiveAccessionRepository<HistoricDatasetEntity> {

}
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.dataset.persistence;

import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.OperationEntity;

import javax.persistence.Entity;

@Entity
public class HistoricLogDatasetEntity extends OperationEntity<Long> {
}
Loading

0 comments on commit abf9e30

Please sign in to comment.