use of uk.ac.bbsrc.tgac.miso.core.data.InstrumentPosition in project miso-lims by miso-lims.
the class DefaultRunService method updateContainerFromNotification.
private boolean updateContainerFromNotification(final Run target, User user, SequencingContainerModel containerModel, String containerSerialNumber, final GetLaneContents getLaneContents, String positionName) throws IOException {
if (LimsUtils.isStringBlankOrNull(containerSerialNumber)) {
return false;
}
final Collection<SequencerPartitionContainer> containers = containerService.listByBarcode(containerSerialNumber);
int laneCount = containerModel.getPartitionCount();
InstrumentPosition position = null;
if (!isStringEmptyOrNull(positionName)) {
position = target.getSequencer().getInstrumentModel().getPositions().stream().filter(pos -> positionName.equals(pos.getAlias())).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("Unknown position '%s' for platform '%s'", positionName, target.getSequencer().getInstrumentModel().getAlias())));
}
switch(containers.size()) {
case 0:
SequencerPartitionContainer newContainer = containerModel.getPlatformType().createContainer();
newContainer.setModel(containerModel);
newContainer.setCreator(user);
newContainer.setIdentificationBarcode(containerSerialNumber);
newContainer.setPartitionLimit(laneCount);
newContainer.setPartitions(IntStream.range(0, laneCount).mapToObj(i -> new PartitionImpl(newContainer, i + 1)).collect(Collectors.toList()));
updatePartitionContents(getLaneContents, newContainer);
RunPosition newRunPos = new RunPosition();
newRunPos.setRun(target);
newRunPos.setContainer(newContainer);
newRunPos.setPosition(position);
target.getRunPositions().clear();
target.getRunPositions().add(newRunPos);
return true;
case 1:
SequencerPartitionContainer container = containers.iterator().next();
boolean isMutated = false;
if (container.getPartitions().size() != laneCount) {
throw new IllegalArgumentException(String.format("The container %s has %d partitions, but %d were detected by the scanner.", containerSerialNumber, container.getPartitions().size(), laneCount));
}
// only update container model from fallback to non-fallback
if (container.getModel().isFallback() && !containerModel.isFallback() && container.getModel().getId() != containerModel.getId()) {
container.setModel(containerModel);
isMutated = true;
}
if (target.getSequencerPartitionContainers().stream().noneMatch(c -> c.getId() == container.getId())) {
target.addSequencerPartitionContainer(container, position);
updatePartitionContents(getLaneContents, container);
isMutated = true;
}
return isMutated;
default:
throw new IllegalArgumentException("Multiple containers with same identifier: " + containerSerialNumber);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.InstrumentPosition in project miso-lims by miso-lims.
the class Dtos method to.
public static InstrumentPosition to(@Nonnull InstrumentPositionDto from) {
InstrumentPosition to = new InstrumentPosition();
setLong(to::setId, from.getId(), false);
setString(to::setAlias, from.getAlias());
return to;
}
use of uk.ac.bbsrc.tgac.miso.core.data.InstrumentPosition in project miso-lims by miso-lims.
the class DefaultInstrumentModelService method loadChildEntities.
@Override
protected void loadChildEntities(InstrumentModel object) throws IOException {
Set<InstrumentPosition> positions = new HashSet<>();
for (InstrumentPosition pos : object.getPositions()) {
if (pos.isSaved()) {
positions.add(instrumentModelStore.getPosition(pos.getId()));
} else {
positions.add(pos);
}
}
object.getPositions().clear();
object.getPositions().addAll(positions);
Set<SequencingContainerModel> models = new HashSet<>();
for (SequencingContainerModel model : object.getContainerModels()) {
models.add(containerModelService.get(model.getId()));
}
object.getContainerModels().clear();
object.getContainerModels().addAll(models);
}
use of uk.ac.bbsrc.tgac.miso.core.data.InstrumentPosition in project miso-lims by miso-lims.
the class EditServiceRecordController method showPage.
public ModelAndView showPage(ServiceRecord record, ModelMap model) throws JsonProcessingException {
if (!record.isSaved()) {
model.put("title", "New Service Record");
} else {
model.put("title", "Service Record " + record.getId());
}
ObjectMapper mapper = new ObjectMapper();
model.put("serviceRecord", record);
model.put("serviceRecordDto", mapper.writeValueAsString(Dtos.asDto(record)));
ArrayNode positions = mapper.createArrayNode();
for (InstrumentPosition pos : record.getInstrument().getInstrumentModel().getPositions()) {
ObjectNode dto = positions.addObject();
dto.put("id", pos.getId());
dto.put("alias", pos.getAlias());
}
model.put("instrumentPositions", mapper.writeValueAsString(positions));
return new ModelAndView("/WEB-INF/pages/editServiceRecord.jsp", model);
}
use of uk.ac.bbsrc.tgac.miso.core.data.InstrumentPosition in project miso-lims by miso-lims.
the class HibernateInstrumentModelDaoIT method testDeletePosition.
@Test
public void testDeletePosition() throws Exception {
long id = 3L;
InstrumentPosition before = (InstrumentPosition) currentSession().get(InstrumentPosition.class, id);
assertNotNull(before);
dao.deletePosition(before);
clearSession();
InstrumentPosition after = (InstrumentPosition) currentSession().get(InstrumentPosition.class, id);
assertNull(after);
}
Aggregations