Skip to content

Commit

Permalink
feat: Predicted piece set (#50)
Browse files Browse the repository at this point in the history
* feat: Predicted piece set

Combined internal pieces into a predicted piece set for use within orders and recieving app

* feat: Fetching prediction pattern sets

Updated url mappings for fetching prediction pattern sets
  • Loading branch information
Jack-Golding authored Jan 18, 2024
1 parent e3b0697 commit f407caa
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package org.olf

import org.olf.PieceGenerationService

import org.olf.Serial
import org.olf.SerialRuleset
import org.olf.PredictedPieceSet
import org.olf.internalPiece.InternalPiece

import com.k_int.okapi.OkapiTenantAwareController

import java.time.LocalDate

import grails.rest.*
Expand All @@ -18,15 +22,14 @@ import java.util.regex.Pattern

@Slf4j
@CurrentTenant
class PredictedPiecesController {
PieceGenerationService pieceGenerationService
class PredictedPieceSetController extends OkapiTenantAwareController<PredictedPieceSet> {
PredictedPieceSetController(){
super(PredictedPieceSet)
}

// PredictedPiecesController(){
// super()
// }

PieceGenerationService pieceGenerationService
// This takes in a JSON shape and outputs predicted pieces without saving domain objects
@Transactional
@Transactional
def generatePredictedPiecesTransient() {
JSONObject data = request.JSON
// SerialRuleset ruleset = new SerialRuleset(data.toMap()).save(flush: true, failOnError: true)
Expand All @@ -38,6 +41,20 @@ class PredictedPiecesController {
}

def generatePredictedPieces() {
JSONObject data = request.JSON
Serial serial = Serial.get(data?.serial?.id)
SerialRuleset ruleset = SerialRuleset.get(data?.ruleset?.id)
ArrayList<InternalPiece> ips = pieceGenerationService.createPiecesTransient(ruleset, LocalDate.parse(data.startDate))

PredictedPieceSet pps = new PredictedPieceSet([
serial: serial,
ruleset: ruleset,
pieces: ips,
note: data?.note,
startDate: data?.startDate
]).save(flush: true, failOnError: true)

respond pps

}
}
}
11 changes: 9 additions & 2 deletions service/grails-app/controllers/org/olf/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ class UrlMappings {

"/serials-management/rulesets" (resources: 'serialRuleset')

"/serials-management/predictedPieces/generate" (controller: 'predictedPieces', action: 'generatePredictedPiecesTransient')
"/serials-management/predictedPieces/create" (controller: 'predictedPieces', action: 'generatePredictedPieces')
"/serials-management/predictedPieces" (resources: 'predictedPieceSet') {
collection {
"/generate" (controller: 'predictedPieceSet', action: 'generatePredictedPiecesTransient')
"/create" (controller: 'predictedPieceSet', action: 'generatePredictedPieces')
}
}



}
}
60 changes: 60 additions & 0 deletions service/grails-app/domain/org/olf/PredictedPieceSet.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.olf

import org.olf.recurrence.Recurrence
import org.olf.internalPiece.InternalPiece

import java.time.LocalDate
import grails.compiler.GrailsCompileStatic
import grails.gorm.MultiTenant
import org.hibernate.Session
import org.hibernate.internal.SessionImpl
import com.k_int.web.toolkit.refdata.CategoryId
import com.k_int.web.toolkit.refdata.Defaults
import com.k_int.web.toolkit.refdata.RefdataValue

class PredictedPieceSet implements MultiTenant<PredictedPieceSet> {

String id
Date lastUpdated
Date dateCreated

LocalDate startDate

Serial serial
SerialRuleset ruleset

String note

static hasMany = [
pieces: InternalPiece
]

static mappedBy = [
pieces: 'owner',
// serial: 'predictedPieceSet',
// ruleset: 'predictedPieceSet',
]

static mapping = {
id column: 'pps_id', generator: 'uuid2', length: 36
lastUpdated column: 'pps_last_updated'
dateCreated column: 'pps_date_created'
version column: 'pps_version'
startDate column: 'pps_start_date'
note column: 'pps_note'

pieces cascade: 'all-delete-orphan'
serial cascade: 'all-delete-orphan'
ruleset cascade: 'all-delete-orphan'
}

static constraints = {
lastUpdated nullable: true
dateCreated nullable: true
note nullable: true
startDate nullable: false
pieces nullable: false
serial nullable: true
ruleset nullable: false
}
}
3 changes: 3 additions & 0 deletions service/grails-app/domain/org/olf/Serial.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Serial implements MultiTenant<Serial> {
recurrence: 'owner'
]

// static belongsTo = [ predictedPieceSet: PredictedPieceSet ]


static mapping = {
id column: 's_id', generator: 'uuid2', length: 36
lastUpdated column: 's_last_updated'
Expand Down
3 changes: 2 additions & 1 deletion service/grails-app/domain/org/olf/SerialRuleset.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class SerialRuleset implements MultiTenant<SerialRuleset> {
]

static belongsTo = [
owner: Serial
owner: Serial,
// predictedPieceSet: PredictedPieceSet
]

static mapping = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.olf.internalPiece

import org.olf.PredictedPieceSet

import grails.gorm.MultiTenant

import java.time.LocalDate
Expand All @@ -14,6 +16,8 @@ public class InternalCombinationPiece extends InternalPiece implements MultiTena

Set<CombinationOrigin> combinationOrigins

static belongsTo = [ owner: PredictedPieceSet ]

static mapping = {
recurrencePieces cascade: 'all-delete-orphan'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.olf.internalPiece

import org.olf.PredictedPieceSet

import grails.gorm.MultiTenant

import java.time.LocalDate
Expand All @@ -13,7 +15,8 @@ public class InternalOmissionPiece extends InternalPiece implements MultiTenant<
LocalDate date

Set<OmissionOrigin> omissionOrigins


static belongsTo = [ owner: PredictedPieceSet ]

static mapping = {
date column: 'iop_date'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.olf.internalPiece

import org.olf.PredictedPieceSet

import java.time.LocalDate

import grails.gorm.MultiTenant
Expand All @@ -10,9 +12,13 @@ public abstract class InternalPiece implements MultiTenant<InternalPiece> {
String templateString
String label

static belongsTo = [ owner: PredictedPieceSet ]


static mapping = {
id column: 'ip_id', generator: 'uuid2', length: 36
version column: 'ip_version'
owner column: 'ip_owner'
templateString column: 'ip_template_string'
label column: 'ip_label'

Expand All @@ -22,7 +28,7 @@ public abstract class InternalPiece implements MultiTenant<InternalPiece> {
static constraints = {
templateString nullable: true
label nullable: true

owner nullable: true
}

// Cannot handle ommited combination, please god no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public class ChronologyDateTMRF extends TemplateMetadataRuleFormat implements Mu
weekday = weekday.toUpperCase()
}

// FIXME IMPLEMENT THIS PROPERLY
Set<Locale> allLanguages = new HashSet<Locale>();
String[] languages = Locale.getISOLanguages();
for (int i = 0; i < languages.length; i++){
Locale loc = new Locale(languages[i]);
allLanguages.add(loc);
}

String monthDay = date.format(DateTimeFormatter.ofPattern('d'))
if(tmrf?.monthDayFormat?.value == 'ordinal'){
monthDay = monthDay + getDayOfMonthSuffix(Integer.parseInt(monthDay))
Expand Down
14 changes: 14 additions & 0 deletions service/grails-app/migrations/create-mod-serials-management.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ databaseChangeLog = {
createTable(tableName: "internal_piece") {
column(name: "ip_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "ip_version", type: "BIGINT") { constraints(nullable: "false") }
column(name: "ip_owner", type: "VARCHAR(36)") { constraints(nullable: "true") }
}
}

Expand Down Expand Up @@ -1316,4 +1317,17 @@ databaseChangeLog = {
column(name: "tmrf_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}

changeSet(author: "Jack-Golding (manual)", id: "20231220-1230-001"){
createTable(tableName: "predicted_piece_set") {
column(name: "pps_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "pps_version", type: "BIGINT") { constraints(nullable: "false") }
column(name: "pps_date_created", type: "timestamp")
column(name: "pps_last_updated", type: "timestamp")
column(name: "pps_start_date", type: "timestamp") { constraints(nullable: "false") }
column(name: "pps_note", type: "TEXT") { constraints(nullable: "true") }
column(name: "ruleset_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
column(name: "serial_id", type: "VARCHAR(36)") { constraints(nullable: "false") }
}
}
}
13 changes: 13 additions & 0 deletions service/grails-app/views/predictedPieceSet/_predictedPieceSet.gson
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import groovy.transform.*
import org.olf.Serial
import groovy.transform.Field

def should_expand = [
'serial',
'ruleset',
'pieces',
]

@Field PredictedPieceSet predictedPieceSet

json g.render(predictedPieceSet, [expand: should_expand])

0 comments on commit f407caa

Please sign in to comment.