Skip to content

Commit

Permalink
Merge pull request #57 from DiamondLightSource/I15_1-563
Browse files Browse the repository at this point in the history
I'm merging now as I don't expect anyone else to chip in at this point. We'll see if it does the job, and if not we'll just have to make another version.
  • Loading branch information
KarlLevik authored Jan 26, 2018
2 parents dfacd31 + b12b59b commit b6ce849
Show file tree
Hide file tree
Showing 9 changed files with 664 additions and 60 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<organization>
<name>Diamond Light Source</name>
</organization>
<version>2.1.1</version>
<version>2.3.0</version>

<packaging>bundle</packaging>

Expand Down Expand Up @@ -147,4 +147,3 @@
</dependencies>

</project>

4 changes: 3 additions & 1 deletion src/main/java/uk/ac/diamond/ispyb/api/IspybXpdfApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
public interface IspybXpdfApi extends Closeable {
List<Sample> retrieveSamplesAssignedForProposal(String proposalCode, Long proposalNumber);
List<SampleGroup> retrieveSampleGroupsForSample(Long sampleId);
List<SampleGroup> retrieveSamplesForSampleGroup(Long sampleGroupId);
List<Sample> retrieveSamplesForSampleGroup(Long sampleGroupId);
List<Component> retrieveComponentsForSampleType(Long sampleTypeId);
List<DataCollectionPlan> retrieveDataCollectionPlansForSample(Long sampleId);
Optional<DataCollectionPlanInfo> retrieveDataCollectionPlanInfoForSample(Long sampleId);
List<ComponentLattice> retrieveComponentLatticesForComponent(Long componentId);
Optional<ContainerInfo> retrieveContainerInfoForId(Long containerId) throws SQLException;
Optional<SampleType> retrieveSampleTypeForSample(Long sampleId) throws SQLException;
List<PDB> retrievePDBsForComponent(Long componentId) throws SQLException;
}
70 changes: 70 additions & 0 deletions src/main/java/uk/ac/diamond/ispyb/api/PDB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*-
*******************************************************************************
* Copyright (c) 2011, 2018 Diamond Light Source Ltd.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* See git history
*******************************************************************************/
package uk.ac.diamond.ispyb.api;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class PDB {
private Long pdbId;
private String name;
private String contents;
private String code;

public Long getPdbId() {
return pdbId;
}

public void setPdbId(Long pdbId) {
this.pdbId = pdbId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getContents() {
return contents;
}

public void setContents(String contents) {
this.contents = contents;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public boolean equals(Object that) {
return EqualsBuilder.reflectionEquals(this, that);
};
}
19 changes: 18 additions & 1 deletion src/main/java/uk/ac/diamond/ispyb/api/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class Sample {
private String sampleTypeName;
private String sampleTypeComments;
private String sampleTypeSpaceGroup;

private Long orderInGroup;
private String typeInGroup;

public Long getSampleId() {
return sampleId;
Expand Down Expand Up @@ -153,6 +154,22 @@ public void setSampleTypeSpaceGroup(String sampleTypeSpaceGroup) {
this.sampleTypeSpaceGroup = sampleTypeSpaceGroup;
}

public Long getOrderInGroup() {
return orderInGroup;
}

public void setOrderInGroup(Long orderInGroup) {
this.orderInGroup = orderInGroup;
}

public String getTypeInGroup() {
return typeInGroup;
}

public void setTypeInGroup(String typeInGroup) {
this.typeInGroup = typeInGroup;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/uk/ac/diamond/ispyb/api/SampleType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*-
*******************************************************************************
* Copyright (c) 2011, 2018 Diamond Light Source Ltd.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* See git history
*******************************************************************************/
package uk.ac.diamond.ispyb.api;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class SampleType {
private Long sampleTypeId;
private Long componentId;
private String name;
private String comments;

public Long getSampleTypeId() {
return sampleTypeId;
}

public void setSampleTypeId(Long sampleTypeId) {
this.sampleTypeId = sampleTypeId;
}

public Long getComponentId() {
return componentId;
}

public void setComponentId(Long componentId) {
this.componentId = componentId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getComments() {
return comments;
}

public void setComments(String comments) {
this.comments = comments;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public boolean equals(Object that) {
return EqualsBuilder.reflectionEquals(this, that);
};
}
18 changes: 16 additions & 2 deletions src/main/java/uk/ac/diamond/ispyb/dao/IspybXpdfDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public List<SampleGroup> retrieveSampleGroupsForSample(Long sampleId){
return templateWrapper.callIspybForListBeans("retrieve_sample_groups_for_sample", SampleGroup.class, map);
}

public List<SampleGroup> retrieveSamplesForSampleGroup(Long sampleGroupId){
public List<Sample> retrieveSamplesForSampleGroup(Long sampleGroupId){
Map<String, Object> map = new HashMap<>();
map.put("sampleGroupId", sampleGroupId);
return templateWrapper.callIspybForListBeans("retrieve_samples_for_sample_group", SampleGroup.class, map);
return templateWrapper.callIspybForListBeans("retrieve_samples_for_sample_group", Sample.class, map);
}

public List<Component> retrieveComponentsForSampleType(Long sampleTypeId){
Expand Down Expand Up @@ -83,6 +83,20 @@ public Optional<ContainerInfo> retrieveContainerInfoForId(Long containerId) thro
return templateWrapper.callIspybForBean("retrieve_container_info_for_id", ContainerInfo.class, map);
}

@Override
public Optional<SampleType> retrieveSampleTypeForSample(Long sampleId) throws SQLException {
Map<String, Object> map = new HashMap<>();
map.put("sampleId", sampleId);
return templateWrapper.callIspybForBean("retrieve_sample_type_for_sample", SampleType.class, map);
}

@Override
public List<PDB> retrievePDBsForComponent(Long componentId) throws SQLException {
Map<String, Object> map = new HashMap<>();
map.put("componentId", componentId);
return templateWrapper.callIspybForListBeans("retrieve_pdbs_for_component", PDB.class, map);
}

@Override
public void close() throws IOException {
try {
Expand Down
83 changes: 66 additions & 17 deletions src/test/java/uk/ac/diamond/ispyb/test/XpdfIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import java.util.List;
import java.util.ArrayList;

import java.nio.file.Files;
import java.nio.file.Paths;

import uk.ac.diamond.ispyb.api.*;
import uk.ac.diamond.ispyb.dao.IspybXpdfDaoFactory;

Expand Down Expand Up @@ -84,23 +87,43 @@ public void testRetrieveSampleGroupsForSample()throws SQLException, IOException,
}

@Test
public void testRetrieveSamplesForSampleGroups()throws SQLException, IOException, InterruptedException {
List<SampleGroup> groups = helper.execute(api -> api.retrieveSamplesForSampleGroup(5L));
List<SampleGroup> sampleGroups = new ArrayList<SampleGroup>();

SampleGroup sampleGroup1 = new SampleGroup();
sampleGroup1.setSampleId(398824L);
sampleGroup1.setOrder(1L);
sampleGroup1.setType(SampleGroupType.BACKGROUND.name());
sampleGroups.add(sampleGroup1);

SampleGroup sampleGroup2 = new SampleGroup();
sampleGroup2.setSampleId(398827L);
sampleGroup2.setOrder(2L);
sampleGroup2.setType(SampleGroupType.SAMPLE.name());
sampleGroups.add(sampleGroup2);

assertThat(groups , is(equalTo(sampleGroups)));
public void testRetrieveSamplesForSampleGroup()throws SQLException, IOException, InterruptedException {
List<Sample> samples = helper.execute(api -> api.retrieveSamplesForSampleGroup(5L));
List<Sample> expected = new ArrayList<Sample>();

Sample sample1 = new Sample();
sample1.setSampleId(398824L);
sample1.setContainerId(34883L);
sample1.setSampleTypeId(333308L);
sample1.setSampleName("XPDF-1");
sample1.setSampleCode("XPDF-0001");
sample1.setSampleComments("Test sample for XPDF");

sample1.setSampleTypeName("SampleType01");
sample1.setSampleTypeComments("sample type comments ...");
sample1.setSampleTypeSpaceGroup("P12121");

sample1.setTypeInGroup("background");
sample1.setOrderInGroup(1L);
expected.add(sample1);

Sample sample2 = new Sample();
sample2.setSampleId(398827L);
sample2.setContainerId(34883L);
sample2.setSampleTypeId(333308L);
sample2.setSampleName("XPDF-2");
sample2.setSampleCode("XPDF-0002");
sample2.setSampleComments("Test sample for XPDF");

sample2.setSampleTypeName("SampleType01");
sample2.setSampleTypeComments("sample type comments ...");
sample2.setSampleTypeSpaceGroup("P12121");

sample2.setTypeInGroup("sample");
sample2.setOrderInGroup(2L);
expected.add(sample2);

assertThat(samples , is(equalTo(expected)));
}

@Test
Expand All @@ -114,6 +137,32 @@ public void testRetrieveComponentsForSampleType()throws SQLException, IOExceptio
assertThat(components, is(equalTo(Arrays.asList(component))));
}

@Test
public void testRetrieveSampleTypeForSample() throws SQLException, IOException, InterruptedException {
Optional<SampleType> sampleType = helper.execute(api -> api.retrieveSampleTypeForSample(398827L));

SampleType expected = new SampleType();
expected.setSampleTypeId(333308L);
expected.setComponentId(123497L);
expected.setName("SampleType01");
expected.setComments("sample type comments ...");

assertThat(sampleType.get(), is(equalTo(expected)));
}

@Test
public void testRetrievePDBsForComponent()throws SQLException, IOException, InterruptedException {
List<PDB> pdbs = helper.execute(api -> api.retrievePDBsForComponent(123497L));

PDB pdb = new PDB();
pdb.setPdbId(6L);
pdb.setName("ceo2");
pdb.setContents(new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir").toString(), "src", "test", "resources", "ceo2.cif"))));

assertThat(pdbs, is(equalTo(Arrays.asList(pdb))));
}


@Test
public void testRetrieveDataCollectionPlansForSample()throws SQLException, IOException, InterruptedException {
List<DataCollectionPlan> components = helper.execute(api -> api.retrieveDataCollectionPlansForSample(398824L));
Expand Down
Loading

0 comments on commit b6ce849

Please sign in to comment.