Skip to content

Commit

Permalink
Merge pull request #125 from folio-org/release/1.1.1
Browse files Browse the repository at this point in the history
chore: Release 1.1.1
  • Loading branch information
Jack-Golding authored Nov 28, 2024
2 parents 5c694ac + 830f1cf commit e2f42da
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 31 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1 2024-11-28
* MODSER-62 Multiple levels of continuous enumeration in a publication pattern result in incorrect numbering
* MODSER-60 Receiving piece count not displaying in predicted piece set

## 1.1.0 2024-10-30
* MODSER-58 Generating template metadata for internal omitted piece
* MODSER-57 Generate/create piece set endpoints to return same objects
Expand Down
2 changes: 1 addition & 1 deletion service/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gradleWrapperVersion=5.4

# Application
appName=mod-serials-management
appVersion=1.1.0
appVersion=1.1.1
okapiInterfaceVersion=1.1
dockerTagSuffix=
dockerRepo=folioci
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.olf.PredictedPieceSet
import org.olf.internalPiece.templateMetadata.TemplateMetadata
import org.olf.internalPiece.templateMetadata.UserConfiguredTemplateMetadata
import org.olf.internalPiece.InternalPiece
import org.olf.templating.LabelTemplateBindings

import com.k_int.okapi.OkapiTenantAwareController

Expand Down Expand Up @@ -47,7 +48,7 @@ class PredictedPieceSetController extends OkapiTenantAwareController<PredictedPi

ArrayList<InternalPiece> ips = pieceGenerationService.createPiecesTransient(ruleset, LocalDate.parse(data.startDate))

TemplateMetadata initialPieceRecurrenceMetadata = pieceLabellingService.generateTemplateMetadataForPiece(ips?.get(0), ips, ruleset?.templateConfig, startingValues)
TemplateMetadata initialPieceRecurrenceMetadata = pieceLabellingService.generateTemplateMetadataForPiece(ips?.get(0), ips, ruleset?.templateConfig, startingValues, null)

// Check for omission rules within the ruleset
// Since we presently only handle omissions OR combinations, only one should ever been applied to the internal pieces
Expand All @@ -56,10 +57,11 @@ class PredictedPieceSetController extends OkapiTenantAwareController<PredictedPi
} else if (!!ruleset?.combination) {
pieceGenerationService.applyCombinationRules(ips, ruleset)
}
pieceLabellingService.setLabelsForInternalPieces(ips, ruleset?.templateConfig, startingValues)
// TODO This should be seperated out into one method setting labels for pieces and another that grabs last piece template bindings
LabelTemplateBindings lastPieceLabelTemplateBindings = pieceLabellingService.setLabelsForInternalPieces(ips, ruleset?.templateConfig, startingValues)

InternalPiece nextPiece = pieceGenerationService.generateNextPiece(ips.get(ips.size()-1), ruleset)
TemplateMetadata continuationPieceRecurrenceMetadata = pieceLabellingService.generateTemplateMetadataForPiece(nextPiece, ips, ruleset?.templateConfig, startingValues)
TemplateMetadata continuationPieceRecurrenceMetadata = pieceLabellingService.generateTemplateMetadataForPiece(nextPiece, ips, ruleset?.templateConfig, startingValues, lastPieceLabelTemplateBindings?.enumerationArray)

PredictedPieceSet pps = new PredictedPieceSet([
ruleset: ruleset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,31 @@ public class EnumerationNumericTMRF extends TemplateMetadataRuleFormat implement
public static EnumerationUCTMT handleFormat (TemplateMetadataRule rule, LocalDate date, int index, EnumerationUCTMT startingValues){
RomanNumeralFormat rnf = new RomanNumeralFormat();

// Array of EnumerationNumericLevels sorted by index
ArrayList<EnumerationNumericLevelTMRF> enltmrfArray = rule?.ruleType?.ruleFormat?.levels?.sort { it?.index }
ArrayList<EnumerationLevelUCTMT> svArray = startingValues?.levels?.sort { it?.index }
// Array of starting values sorted by index
ArrayList<EnumerationLevelUCTMT> levelStartingValueArray = startingValues?.levels?.sort { it?.index }
ArrayList<EnumerationLevelUCTMT> result = []

Integer adjustedIndex = 0
Integer divisor = 1

// Will always be true for the lowest level of enumeration, decides whether subsequent levels should be incremented
Boolean shouldIncrement = true
// Iterate through the EnumerationNumericLevels starting at the lowest level
for(int i=enltmrfArray?.size()-1; i>=0; i--){
if(svArray?.getAt(i)?.value !== null){
adjustedIndex = adjustedIndex + ((svArray.getAt(i)?.value as Integer - 1)*divisor)
}

Integer value = 0
for(int j=0; j<=index+adjustedIndex; j++){
if(j % divisor == 0){
value++
// Set value to previous pieces corresponding value
Integer value = levelStartingValueArray?.getAt(i)?.rawValue as Integer ?: 1
// Only calculate if we're past the first piece, otherwise use starting values
if(index != 0){
//If previous level has set flag to true, increment
//Always incremement on lowest level then set to false so higher levels should only ever increment with permission from lower levels
if(shouldIncrement == true){
if (value % enltmrfArray[i]?.units != 0) {
shouldIncrement = false
}
value ++
}
}

// If the number should be reset on every cycle, calculate its actual value
if(enltmrfArray[i]?.sequence?.value == 'reset'){
if(value%enltmrfArray[i]?.units == 0){
value = enltmrfArray[i]?.units
Expand All @@ -86,8 +92,6 @@ public class EnumerationNumericTMRF extends TemplateMetadataRuleFormat implement
valueFormat: enltmrfArray[i]?.format,
index: i
])

divisor = enltmrfArray[i]?.units*divisor
}
return new EnumerationUCTMT([levels: result.reverse()])
}
Expand Down
61 changes: 50 additions & 11 deletions service/grails-app/services/org/olf/PieceLabellingService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,64 @@ public class PieceLabellingService {


// This needs to take in an individual piece and ooutput a String label
public String generateTemplatedLabelForPiece(InternalPiece piece, ArrayList<InternalPiece> internalPieces, TemplateConfig templateConfig, ArrayList<UserConfiguredTemplateMetadata> startingValues) {
Template template = hte.createTemplate(templateConfig.templateString);
// Template template = hte.createTemplate("EA {{chronology1.year}} {{chronologyArray.0.year}} {{test}}")

// PreviousLabelTemplateBindings will b null for first piece
public LabelTemplateBindings generateTemplateBindingsForPiece(
InternalPiece piece,
ArrayList<InternalPiece> internalPieces,
TemplateConfig templateConfig,
ArrayList<UserConfiguredTemplateMetadata> startingValues,
LabelTemplateBindings previousLabelTemplateBindings
){
StandardTemplateMetadata standardTM = generateStandardMetadata(piece, internalPieces)
// Having to enforce a sort here
Set<TemplateMetadataRule> sortedRules = templateConfig.rules?.sort{ it.index }
ArrayList<UserConfiguredTemplateMetadata> sortedStartingValues = startingValues?.sort{ it.index }

// Makig assumption that chronologies dont have starting values
ArrayList<ChronologyUCTMT> chronologyArray = generateChronologyMetadata(standardTM, sortedRules)
ArrayList<EnumerationUCTMT> enumerationArray = generateEnumerationMetadata(standardTM, sortedRules, sortedStartingValues)
ArrayList<EnumerationUCTMT> enumerationArray = generateEnumerationMetadata(
standardTM,
sortedRules,
sortedStartingValues,
previousLabelTemplateBindings?.enumerationArray
)

LabelTemplateBindings ltb = new LabelTemplateBindings()
ltb.setupChronologyArray(chronologyArray)
ltb.setupEnumerationArray(enumerationArray)
ltb.setupStandardTM(standardTM)

return ltb
}

public String generateLabelForPiece(LabelTemplateBindings ltb, String templateString){
Template template = hte.createTemplate(templateString);
// Template template = hte.createTemplate("EA {{chronology1.year}} {{chronologyArray.0.year}} {{test}}")

return template.make(ltb).with {
StringWriter sw = new StringWriter()
writeTo(sw)
sw.toString()
}
}

public void setLabelsForInternalPieces(ArrayList<InternalPiece> internalPieces, TemplateConfig templateConfig, ArrayList<UserConfiguredTemplateMetadata> startingValues) {
//Returns the last label template binding for use in next piece
public LabelTemplateBindings setLabelsForInternalPieces(ArrayList<InternalPiece> internalPieces, TemplateConfig templateConfig, ArrayList<UserConfiguredTemplateMetadata> startingValues) {
ListIterator<InternalPiece> iterator = internalPieces?.listIterator()
LabelTemplateBindings previousLabelTemplateBindings = null
while(iterator.hasNext()){
InternalPiece currentPiece = iterator.next()
if(currentPiece instanceof InternalRecurrencePiece || currentPiece instanceof InternalCombinationPiece){
String label = generateTemplatedLabelForPiece(currentPiece, internalPieces, templateConfig, startingValues)
// String label = generateTemplatedLabelForPiece(currentPiece, internalPieces, templateConfig, startingValues)
LabelTemplateBindings ltb = generateTemplateBindingsForPiece(currentPiece, internalPieces, templateConfig, startingValues, previousLabelTemplateBindings)
String label = generateLabelForPiece(ltb, templateConfig?.templateString)
currentPiece.label = label
currentPiece.templateString = templateConfig?.templateString
// Not a huge fan of overwriting a previous binding
previousLabelTemplateBindings = ltb
}
}
return previousLabelTemplateBindings
}

// This probably doesnt belong here, potentially in different service
Expand Down Expand Up @@ -160,25 +184,40 @@ public class PieceLabellingService {
return chronologyTemplateMetadataArray
}

public ArrayList<EnumerationUCTMT> generateEnumerationMetadata(StandardTemplateMetadata standardTM, Set<TemplateMetadataRule> templateMetadataRules, ArrayList<UserConfiguredTemplateMetadata> startingValues) {
public ArrayList<EnumerationUCTMT> generateEnumerationMetadata(
StandardTemplateMetadata standardTM,
Set<TemplateMetadataRule> templateMetadataRules,
ArrayList<UserConfiguredTemplateMetadata> startingValues,
ArrayList<EnumerationUCTMT> previousEnumerationArray
) {
ArrayList<EnumerationUCTMT> enumerationTemplateMetadataArray = []
Iterator<TemplateMetadataRule> iterator = templateMetadataRules?.iterator()
// TODO This should get neater once enumeration/chronology are seperated
int enumerationIndex = 0
while(iterator?.hasNext()){
TemplateMetadataRule currentMetadataRule = iterator.next()
String templateMetadataType = RGX_METADATA_RULE_TYPE.matcher(currentMetadataRule?.templateMetadataRuleType?.value).replaceAll { match -> match.group(1).toUpperCase() }
if(templateMetadataType == 'enumeration'){
Class<? extends TemplateMetadataRuleType> tmrte = Class.forName("org.olf.templateConfig.templateMetadataRule.${templateMetadataType.capitalize()}TemplateMetadataRule")
EnumerationUCTMT ruleStartingValues = startingValues.getAt(currentMetadataRule?.index)?.metadataType
// previousEnumerationArray might be null
EnumerationUCTMT ruleStartingValues = previousEnumerationArray ? previousEnumerationArray?.getAt(enumerationIndex) : startingValues.getAt(currentMetadataRule?.index)?.metadataType
EnumerationUCTMT enumerationUCTMT = tmrte.handleType(currentMetadataRule, standardTM.date, standardTM.index, ruleStartingValues)

enumerationTemplateMetadataArray << enumerationUCTMT
enumerationIndex++
}
}
return enumerationTemplateMetadataArray
}


public TemplateMetadata generateTemplateMetadataForPiece(InternalPiece piece, ArrayList<InternalPiece> internalPieces, TemplateConfig templateConfig, ArrayList<UserConfiguredTemplateMetadata> startingValues){
public TemplateMetadata generateTemplateMetadataForPiece(
InternalPiece piece,
ArrayList<InternalPiece> internalPieces,
TemplateConfig templateConfig,
ArrayList<UserConfiguredTemplateMetadata> startingValues,
ArrayList<EnumerationUCTMT> previousEnumerationArray
){
// TODO alot of the variable here can be renamed for easier maintainability
ArrayList<InternalPiece> ipsPlusNext = internalPieces.clone()
ipsPlusNext << piece
Expand All @@ -194,7 +233,7 @@ public class PieceLabellingService {
String templateMetadataType = RGX_METADATA_RULE_TYPE.matcher(currentMetadataRule?.templateMetadataRuleType?.value).replaceAll { match -> match.group(1).toUpperCase() }
Class<? extends TemplateMetadataRuleType> tmrt = Class.forName("org.olf.templateConfig.templateMetadataRule.${templateMetadataType.capitalize()}TemplateMetadataRule")
if(templateMetadataType == 'enumeration'){
EnumerationUCTMT ruleStartingValues = startingValues.getAt(currentMetadataRule?.index)?.metadataType
EnumerationUCTMT ruleStartingValues = previousEnumerationArray ? previousEnumerationArray?.getAt(currentMetadataRule?.index) : startingValues.getAt(currentMetadataRule?.index)?.metadataType
EnumerationUCTMT enumerationUCTMT = tmrt.handleType(currentMetadataRule, standardTM.date, standardTM.index, ruleStartingValues)

// FIXME upon creation of a new UserConfiguredTemplateMetadata we use the refdata binding previously seen in recurrence, omission etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import groovy.transform.Field
def should_expand = [
'recurrencePieces',
'combinationOrigins',
'receivingPieces'
]

@Field InternalCombinationPiece internalCombinationPiece
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import groovy.transform.*
import org.olf.internalPiece.InternalOmissionPiece
import groovy.transform.Field

// We may wish to remove receivingPieces from this in the future
def should_expand = [
'omissionOrigins',
'receivingPieces'
]

@Field InternalOmissionPiece internalOmissionPiece
Expand Down
2 changes: 0 additions & 2 deletions service/grails-app/views/internalPiece/_internalPiece.gson
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import org.olf.internalPiece.InternalPiece
import groovy.transform.Field
import org.grails.orm.hibernate.cfg.GrailsHibernateUtil

def should_expand = ['receivingPieces', 'templateMetadata']

@Field InternalPiece internalPiece
internalPiece = GrailsHibernateUtil.unwrapIfProxy(internalPiece) as InternalPiece

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import groovy.transform.Field

def should_expand = [
'recurrenceRule',
'receivingPieces'
]

@Field InternalRecurrencePiece internalRecurrencePiece
Expand Down

0 comments on commit e2f42da

Please sign in to comment.