Skip to content

Commit

Permalink
DROTH-3109 improved lane split functionality after review
Browse files Browse the repository at this point in the history
  • Loading branch information
SWJPTulijoki committed Apr 27, 2022
1 parent d943c3e commit 660d603
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
15 changes: 9 additions & 6 deletions UI/src/model/selectedLaneModelling.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@
return lane.endMeasure;
});

var charCount = 0;
for (var i = 0; i < lanesSortedByEndMeasure.length; i++) {
if (_.includes(laneCodesToPutMarkers, getLaneCodeValue(lanesSortedByEndMeasure[i]).toString())) {
lanesSortedByEndMeasure[i].marker = String.fromCharCode(charCount + 65);
charCount += 1;
_.forEach(laneCodesToPutMarkers, function (laneCode) {
var characterCounterForLaneMarker = 0;
for (var i = 0; i < lanesSortedByEndMeasure.length; i++) {
if (laneCode == getLaneCodeValue(lanesSortedByEndMeasure[i]).toString()) {
//The integer value of 'A' is 65, so every increment in the counter gives the next letter of the alphabet.
lanesSortedByEndMeasure[i].marker = String.fromCharCode(characterCounterForLaneMarker + 65);
characterCounterForLaneMarker += 1;
}
}
}
});

return lanesSortedByEndMeasure;
};
Expand Down
16 changes: 13 additions & 3 deletions UI/src/view/linear_asset/laneModellingLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,17 @@
return property.publicId === "lane_code";
}).values).value;

return !selectedLane.isOuterLane(laneNumber) || laneNumber == 1 || (!_.isUndefined(properties) &&
properties.selectedLinks.length > 1 && _.isUndefined(properties.marker)) || selectedLane.isAddByRoadAddress();
var uniqueSelectedRoadLinkIds = _.uniq(_.map(properties.selectedLinks, function (selectedLink) {
return selectedLink.linkId;
}));
if(_.isUndefined(uniqueSelectedRoadLinkIds)) {
return true;
}

var SelectedLaneCannotBeCut = !selectedLane.isOuterLane(laneNumber) || laneNumber == 1 || laneNumber != selectedLane.getCurrentLaneNumber() ||
uniqueSelectedRoadLinkIds.length > 1 || selectedLane.isAddByRoadAddress();

return SelectedLaneCannotBeCut;
})
.map(function(feature) {
var closestP = feature.getGeometry().getClosestPoint(point);
Expand Down Expand Up @@ -119,7 +128,8 @@
return property.publicId === "lane_code";
}).values).value;

return !selectedLane.isOuterLane(laneNumber) || laneNumber == 1 || selectedLane.isAddByRoadAddress();
return !selectedLane.isOuterLane(laneNumber) || laneNumber == 1 ||
laneNumber != selectedLane.getCurrentLaneNumber() || selectedLane.isAddByRoadAddress();
});

selected = _.sortBy(selected, function (lane) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ trait LaneOperations {
val oldLane = allExistingLanes.find(laneAux => laneAux.laneCode == lane.laneCode && laneAux.linkId == linkId)
.getOrElse(throw new InvalidParameterException(s"LinkId: $linkId dont have laneCode: ${lane.laneCode} for update!"))

if (linkIds.size == 1 && lane.startMeasure == laneToUpdate.startMeasure && lane.startMeasure == laneToUpdate.startMeasure && lane.laneCode == laneToUpdateCode) {
val isExactlyMatchingSingleLinkLane = (lane: PersistedLane) => linkIds.size == 1 &&
lane.startMeasure == laneToUpdate.startMeasure && lane.startMeasure == laneToUpdate.startMeasure && lane.laneCode == laneToUpdateCode

if (isExactlyMatchingSingleLinkLane(lane)) {
var newLaneID = lane.id
if (isSomePropertyDifferent(lane, laneToUpdate.properties)) {
val persistedLaneToUpdate = PersistedLane(lane.id, linkId, sideCode, laneToUpdateCode, lane.municipalityCode,
Expand Down Expand Up @@ -925,35 +928,32 @@ trait LaneOperations {
}

def createMultiLanesOnLink(updateNewLanes: Seq[NewLane], linkIds: Set[Long], sideCode: Int, username: String): Seq[Long] = {
if (updateNewLanes.size == 0) {
return Seq()
}
// Get all lane codes from lanes to update
val laneCodesToModify = updateNewLanes.map { newLane => getLaneCode(newLane).toInt }
val startMeasureToModify = updateNewLanes.map(newLane => newLane.startMeasure).reduce(_ min _)
val endMeasureToModify = updateNewLanes.map(newLane => newLane.endMeasure).reduce(_ max _)
//Fetch from db the existing lanes that the new lanes will replace
val oldLanes = dao.fetchLanesByLinkIdsAndLaneCode(linkIds.toSeq, laneCodesToModify).filter(lane => lane.sideCode == sideCode
&& lane.startMeasure >= startMeasureToModify && lane.endMeasure <= endMeasureToModify)

val laneCodesToModify = updateNewLanes.map { newLane => getLaneCode(newLane).toInt }
val oldLanes = dao.fetchLanesByLinkIdsAndLaneCode(linkIds.toSeq, laneCodesToModify).filter(lane => lane.sideCode == sideCode)
val newLanesByLaneCode = updateNewLanes.groupBy(il => getLaneCode(il).toInt)

//By lane check if exist something to modify
newLanesByLaneCode.flatMap { case (laneCode, lanesToUpdate) =>
val oldLanesByCode = oldLanes.filter(_.laneCode == laneCode)


if (lanesToUpdate.size > oldLanesByCode.size) {
if (lanesToUpdate.size >= 2) {
//When one or more lanes are cut to smaller pieces
val newLanesIDs = lanesToUpdate.map { lane =>
create(Seq(lane), linkIds, sideCode, username).head
}

def isWithinRangeToExpire(newLanes: Seq[NewLane], oldLane: PersistedLane): Boolean = {
newLanes.filter(newLane => newLane.startMeasure == oldLane.startMeasure || newLane.endMeasure == oldLane.endMeasure).size == 2
}

newLanesIDs.foreach { newLane =>
moveToHistory(oldLanesByCode.head.id, Some(newLane), true, false, username)
}
oldLanes.foreach {oldLane =>
dao.deleteEntryLane(oldLane.id)
if (isWithinRangeToExpire(lanesToUpdate, oldLane)) {
dao.deleteEntryLane(oldLane.id)
}
}

newLanesIDs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,34 @@ class LaneServiceSpec extends LaneTestSupporter {
}
}

test("Split lane in both ends, leaving the middle untouched") {
runWithRollback {
val mainLane1 = NewLane(0, 0, 500, 745, false, false, lanePropertiesValues1)
val subLane2SplitA = NewLane(0, 0, 150, 745, false, false, lanePropertiesValues2)
val subLane2SplitB = NewLane(0, 150, 350, 745, false, false, lanePropertiesValues2)
val subLane2SplitC = NewLane(0, 350, 500, 745, false, false, lanePropertiesValues2)
val laneIds = ServiceWithDao.create(Seq(mainLane1, subLane2SplitA, subLane2SplitB, subLane2SplitC), Set(100L), 1, usernameTest)

val initialLanes = laneDao.fetchLanesByLinkIdsAndLaneCode(Seq(100L), Seq(1, 2), false)
initialLanes.size should be(4)

val existingMainLane1 = NewLane(laneIds(0), 0, 500, 745, false, false, lanePropertiesValues1)
val newSubLane2SplitA1 = NewLane(0, 0, 50, 745, false, false, lanePropertiesValues2)
val newSubLane2SplitA2 = NewLane(0, 50, 150, 745, false, false, lanePropertiesValues2)
val existingSubLane2SplitB = NewLane(laneIds(2), 150, 350, 745, false, false, lanePropertiesValues2)
val newSubLane2SplitC1 = NewLane(0, 350, 450, 745, false, false, lanePropertiesValues2)
val newSubLane2SplitC2 = NewLane(0, 450, 500, 745, false, false, lanePropertiesValues2)

ServiceWithDao.processNewLanes(Set(existingMainLane1, newSubLane2SplitA1, newSubLane2SplitA2, existingSubLane2SplitB, newSubLane2SplitC1, newSubLane2SplitC2), Set(100L), 1, usernameTest, Seq())

val currentLanes = laneDao.fetchLanesByLinkIdsAndLaneCode(Seq(100L), Seq(1, 2), false)
currentLanes.size should be(6)

val expiredLanes = laneHistoryDao.fetchHistoryLanesByLinkIdsAndLaneCode(Seq(100L), Seq(2), true)
expiredLanes.size should be(4)
}
}

test("Change properties of several splits") {
runWithRollback {
val mainLane1 = NewLane(0, 0, 500, 745, false, false, lanePropertiesValues1)
Expand Down

0 comments on commit 660d603

Please sign in to comment.