Skip to content

Commit

Permalink
Merge branch 'v4.2.x' of https://github.com/krishagni/openspecimen in…
Browse files Browse the repository at this point in the history
…to v4.2.x
  • Loading branch information
lomadi committed Dec 3, 2017
2 parents ef65712 + 5a60b2e commit ce6b9b2
Show file tree
Hide file tree
Showing 88 changed files with 1,992 additions and 785 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<param name="enumClass">
com.krishagni.catissueplus.core.biospecimen.domain.CollectionProtocol$VisitCollectionMode
</param>
<param name="type">12</param>
</type>
</property>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
delete from
com.krishagni.catissueplus.core.administrative.domain.StorageContainerPosition p
where
p.reservationTime < :expireTime
(p.blocked is null or p.blocked = 0) and p.reservationTime < :expireTime
]]>
</query>

Expand Down Expand Up @@ -247,7 +247,7 @@
where
c.store_specimens = 1 and
c.activity_status = 'Active' and
(p.reservation_time is null or p.reservation_time > :reservedLaterThan) and
(p.reservation_time is null or p.reservation_time > :reservedLaterThan or p.blocked = 1) and
(
allowed_cps.cp_id = :cpId or
(allowed_cps.cp_id is null and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="false">
<class name="com.krishagni.catissueplus.core.administrative.domain.StorageContainerPosition" table="OS_CONTAINER_POSITIONS" batch-size="25">
Expand All @@ -23,22 +23,12 @@

<property name="reservationTime" column="RESERVATION_TIME"/>

<many-to-one
name="container"
class="com.krishagni.catissueplus.core.administrative.domain.StorageContainer"
column="STORAGE_CONTAINER_ID"/>

<many-to-one
name="occupyingSpecimen"
class="com.krishagni.catissueplus.core.biospecimen.domain.Specimen"
column="OCCUPYING_SPECIMEN_ID"
unique="true"
cascade="save-update"/>

<many-to-one
name="occupyingContainer"
class="com.krishagni.catissueplus.core.administrative.domain.StorageContainer"
column="OCCUPYING_CONTAINER_ID"
unique="true"/>
<property name="blocked" column="BLOCKED"/>

<many-to-one name="container" column="STORAGE_CONTAINER_ID"/>

<many-to-one name="occupyingSpecimen" column="OCCUPYING_SPECIMEN_ID" unique="true" cascade="save-update"/>

<many-to-one name="occupyingContainer" column="OCCUPYING_CONTAINER_ID" unique="true"/>
</class>
</hibernate-mapping>
7 changes: 7 additions & 0 deletions WEB-INF/resources/db/4.2/audit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@
<column name="visitCollectionMode_MOD" type="${bit.type}"/>
</addColumn>
</changeSet>

<changeSet author="vpawar" id="Audit and track changes to container slot blocking">
<addColumn tableName="OS_CONTAINER_POSITIONS_AUD">
<column name="BLOCKED" type="${boolean.type}"/>
<column name="blocked_MOD" type="${boolean.type}"/>
</addColumn>
</changeSet>
</databaseChangeLog>
6 changes: 6 additions & 0 deletions WEB-INF/resources/db/4.2/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,10 @@
cpr.identifier
</createView>
</changeSet>

<changeSet author="vpawar" id="Boolean indicating whether the container position is blocked">
<addColumn tableName="OS_CONTAINER_POSITIONS">
<column name="BLOCKED" type="${boolean.type}"/>
</addColumn>
</changeSet>
</databaseChangeLog>
10 changes: 8 additions & 2 deletions WEB-INF/resources/errors/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ storage_container_ref_entity_found=One or more entities refer to the container.

storage_container_cannot_hold_specimen=Container {0} can not hold specimen {1} due to restrictions.

storage_container_invalid_positions=Container position is invalid.

storage_container_cannot_hold_container=Container {0} can not hold {1} due to restrictions.

storage_container_invalid_entity_type=Containers can hold specimens or containers but not {0}.
Expand All @@ -140,6 +138,8 @@ storage_container_specimen_types=Allowed Specimen Types

storage_container_not_stored=Not Stored

storage_container_cell_blocked=Blocked

storage_container_invalid_cps=One or more collection protocols do not belong to container site.

storage_container_type_required=Container type is required.
Expand All @@ -164,6 +164,12 @@ storage_container_inv_cont_sel_strategy=Invalid container auto selection strateg

storage_container_inv_cont_sel_rule=Invalid container auto allocation rule {0}.

storage_container_dl_pos_blk_np=Blocking of positions in dimensionless container {0} is not permitted.

storage_container_inv_pos=Invalid container {0} position ({2}, {1})

storage_container_pos_occupied=Container {0} position ({2}, {1}) is occupied.

####################
# Container Type Module
####################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
Expand All @@ -36,7 +38,7 @@
@Audited
public class StorageContainer extends BaseEntity {
private static final String ENTITY_NAME = "storage_container";

public static final String NUMBER_LABELING_SCHEME = "Numbers";

public static final String UPPER_CASE_ALPHA_LABELING_SCHEME = "Alphabets Upper Case";
Expand Down Expand Up @@ -133,10 +135,6 @@ public StorageContainer() {
ancestorContainers.add(this);
}

public static String getEntityName() {
return ENTITY_NAME;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -535,8 +533,8 @@ public StorageContainerPosition createPosition(String posOne, String posTwo) {
return createPosition(null, null, null, null);
}

int posOneOrdinal = toOrdinal(getColumnLabelingScheme(), posOne);
int posTwoOrdinal = toOrdinal(getRowLabelingScheme(), posTwo);
Integer posOneOrdinal = toOrdinal(getColumnLabelingScheme(), posOne);
Integer posTwoOrdinal = toOrdinal(getRowLabelingScheme(), posTwo);
return createPosition(posOneOrdinal, posOne, posTwoOrdinal, posTwo);
}

Expand Down Expand Up @@ -646,6 +644,14 @@ public boolean isPositionOccupied(String posOne, String posTwo) {
int posTwoOrdinal = toOrdinal(getRowLabelingScheme(), posTwo);
return getOccupiedPosition(posOneOrdinal, posTwoOrdinal) != null;
}

public boolean isPositionOccupied(int posOneOrdinal, int posTwoOrdinal) {
if (isDimensionless()) {
return false;
}

return getOccupiedPosition(posOneOrdinal, posTwoOrdinal) != null;
}

public boolean canSpecimenOccupyPosition(Long specimenId, String posOne, String posTwo) {
return canOccupyPosition(true, specimenId, posOne, posTwo, false);
Expand Down Expand Up @@ -728,19 +734,6 @@ public StorageContainerPosition getReservedPosition(String row, String column, S
return reservedPos;
}

public static boolean isValidScheme(String scheme) {
if (StringUtils.isBlank(scheme)) {
return false;
}

return scheme.equals(NUMBER_LABELING_SCHEME) ||
scheme.equals(UPPER_CASE_ALPHA_LABELING_SCHEME) ||
scheme.equals(LOWER_CASE_ALPHA_LABELING_SCHEME) ||
scheme.equals(UPPER_CASE_ROMAN_LABELING_SCHEME) ||
scheme.equals(LOWER_CASE_ROMAN_LABELING_SCHEME);
}


public void validateRestrictions() {
StorageContainer parent = getParentContainer();
if (parent != null && !parent.canContain(this)) {
Expand Down Expand Up @@ -816,7 +809,7 @@ public void delete() {
if (specimensCnt > 0) {
throw OpenSpecimenException.userError(StorageContainerErrorCode.REF_ENTITY_FOUND);
}

deleteWithoutCheck();
}

Expand Down Expand Up @@ -844,7 +837,7 @@ public void assignPositions(Collection<StorageContainerPosition> positions, bool

Set<Long> specimenIds = Collections.emptySet();
if (vacateOccupant) {
specimenIds = new HashSet<Long>();
specimenIds = new HashSet<>();
for (StorageContainerPosition position : positions) {
if (position.getOccupyingSpecimen() != null) {
specimenIds.add(position.getOccupyingSpecimen().getId());
Expand Down Expand Up @@ -885,6 +878,68 @@ public void assignPositions(Collection<StorageContainerPosition> positions, bool
}
}
}

public List<StorageContainerPosition> reservePositions(int numPositions) {
return reservePositions(getReservationId(), Calendar.getInstance().getTime(), numPositions);
}

public List<StorageContainerPosition> reservePositions(String reservationId, Date reservationTime, int numPositions) {
List<StorageContainerPosition> reservedPositions = new ArrayList<>();

while (numPositions != 0) {
StorageContainerPosition pos = nextAvailablePosition(true);
if (pos == null) {
break;
}

pos.setReservationId(reservationId);
pos.setReservationTime(reservationTime);
reservedPositions.add(pos);

--numPositions;
if (!isDimensionless()) {
addPosition(pos);
}
}

return reservedPositions;
}

public void blockPositions(Collection<StorageContainerPosition> positions) {
if (isDimensionless()) {
throw OpenSpecimenException.userError(StorageContainerErrorCode.DL_POS_BLK_NP, getName());
}

Date reservationTime = Calendar.getInstance().getTime();
String reservationId = getReservationId();
for (StorageContainerPosition position : positions) {
if (!position.isSpecified() || !areValidPositions(position.getPosOneOrdinal(), position.getPosTwoOrdinal())) {
throw OpenSpecimenException.userError(StorageContainerErrorCode.INV_POS, getName(), position.getPosOne(), position.getPosTwo());
}

if (isPositionOccupied(position.getPosOneOrdinal(), position.getPosTwoOrdinal())) {
throw OpenSpecimenException.userError(StorageContainerErrorCode.POS_OCCUPIED, getName(), position.getPosOne(), position.getPosTwo());
}

position.setBlocked(true);
position.setReservationTime(reservationTime);
position.setReservationId(reservationId);
addPosition(position);
}
}

public void unblockPositions(Collection<StorageContainerPosition> positions) {
if (isDimensionless()) {
throw OpenSpecimenException.userError(StorageContainerErrorCode.DL_POS_BLK_NP, getName());
}

for (StorageContainerPosition position : positions) {
StorageContainerPosition occupied = getOccupiedPosition(position.getPosOneOrdinal(), position.getPosTwoOrdinal());
if (occupied != null && occupied.isBlocked()) {
occupied.vacate();
}
}
}

public StorageContainer copy() {
StorageContainer copy = new StorageContainer();
Expand Down Expand Up @@ -951,6 +1006,26 @@ public void processList(ContainerStoreList list) {
getAutoFreezerProvider().getInstance().processList(list);
}

public static String getEntityName() {
return ENTITY_NAME;
}

public static boolean isValidScheme(String scheme) {
if (StringUtils.isBlank(scheme)) {
return false;
}

return scheme.equals(NUMBER_LABELING_SCHEME) ||
scheme.equals(UPPER_CASE_ALPHA_LABELING_SCHEME) ||
scheme.equals(LOWER_CASE_ALPHA_LABELING_SCHEME) ||
scheme.equals(UPPER_CASE_ROMAN_LABELING_SCHEME) ||
scheme.equals(LOWER_CASE_ROMAN_LABELING_SCHEME);
}

public static String getReservationId() {
return UUID.randomUUID().toString();
}

private void deleteWithoutCheck() {
getChildContainers().forEach(StorageContainer::deleteWithoutCheck);

Expand Down Expand Up @@ -1109,7 +1184,7 @@ private void updateContainerLocation(Site otherSite, StorageContainer otherParen
if (cycleExistsInHierarchy(otherParentContainer)) {
throw OpenSpecimenException.userError(StorageContainerErrorCode.HIERARCHY_CONTAINS_CYCLE);
}

if (position != null) {
position.update(otherPos);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class StorageContainerPosition implements Comparable<StorageContainerPosi

private Date reservationTime;

private Boolean blocked;

public Long getId() {
return id;
}
Expand Down Expand Up @@ -119,6 +121,18 @@ public void setReservationTime(Date reservationTime) {
this.reservationTime = reservationTime;
}

public Boolean getBlocked() {
return blocked;
}

public void setBlocked(Boolean blocked) {
this.blocked = blocked;
}

public boolean isBlocked() {
return blocked != null && blocked;
}

public void update(StorageContainerPosition other) {
//
// Ideally when container changes, we should first remove it from old container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public enum StorageContainerErrorCode implements ErrorCode {
INVALID_ENTITY_TYPE,

OCCUPYING_ENTITY_ID_OR_NAME_REQUIRED,
INVALID_POSITIONS,

INV_POS,

INVALID_CPS,

Expand All @@ -74,7 +74,11 @@ public enum StorageContainerErrorCode implements ErrorCode {

INV_CONT_SEL_STRATEGY,

INV_CONT_SEL_RULE;
INV_CONT_SEL_RULE,

DL_POS_BLK_NP,

POS_OCCUPIED;

@Override
public String code() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import java.util.ArrayList;
import java.util.List;

public class AssignPositionsOp {
public class PositionsDetail {
private Long containerId;

private String containerName;

private boolean vacateOccupant;

private List<StorageContainerPositionDetail> positions = new ArrayList<StorageContainerPositionDetail>();
private List<StorageContainerPositionDetail> positions = new ArrayList<>();

public Long getContainerId() {
return containerId;
Expand Down
Loading

0 comments on commit ce6b9b2

Please sign in to comment.