Skip to content

Commit

Permalink
fixed METS Header Agents saved state not being correctly recovered; f…
Browse files Browse the repository at this point in the history
…ixes #262
  • Loading branch information
chalkos committed Apr 19, 2017
1 parent 793cc72 commit 069b5df
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/roda/rodain/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ public final class Constants {
public static final String I18N_ASSOCIATE = "associate";
public static final String I18N_BACK = "back";
public static final String I18N_CANCEL = "cancel";
public static final String I18N_CLEAR = "clear";
public static final String I18N_CLOSE = "close";
public static final String I18N_COLLAPSE = "collapse";
public static final String I18N_CONFIRM = "confirm";
Expand Down
101 changes: 50 additions & 51 deletions src/main/java/org/roda/rodain/ui/creation/CreationModalMETSHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.sun.javafx.scene.control.skin.ScrollPaneSkin;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -89,7 +87,7 @@ public CreationModalMETSHeader(CreationModalStage stage, CreationModalPreparatio
getStyleClass().add(Constants.CSS_SIPCREATOR);

createTop();
createCenter();
createAndAddCenter(true);
createBottom();

stage.sizeToScene();
Expand All @@ -110,7 +108,54 @@ private void createTop() {
setTop(top);
}

private void createCenter() {
private void createBottom() {
HBox bottom = new HBox();
bottom.setPadding(new Insets(0, 10, 10, 10));
bottom.setAlignment(Pos.CENTER_LEFT);

Button back = new Button(I18n.t(Constants.I18N_BACK));
back.setOnAction(actionEvent -> {
stage.setRoot(previousPanel);
stage.sizeToScene();
});

Button clear = new Button(I18n.t(Constants.I18N_CLEAR));
clear.setOnAction(actionEvent -> createAndAddCenter(false));

start = new Button(I18n.t(Constants.I18N_START));
start.setOnAction(actionEvent -> {
IPHeader header = new IPHeader();
boolean valid = true;

for (AbstractGroup fieldGroup : fieldGroups) {
if (!fieldGroup.validate()) {
valid = false;
} else {
if (fieldGroup instanceof StatusGroup) {
((StatusGroup) fieldGroup).addStatusToHeader(header);
} else if (fieldGroup instanceof AltRecordGroup) {
((AltRecordGroup) fieldGroup).addAltRecordsToHeader(header);
} else if (fieldGroup instanceof AgentGroup) {
((AgentGroup) fieldGroup).addAgentsToHeader(header);
}
}
}

if (valid) {
ConfigurationManager.serialize(header, sipType.name() + Constants.RODAIN_SERIALIZE_FILE_METS_HEADER_SUFFIX);
stage.startCreation(outputFolder, exportAll, exportItems, sipNameBuilder, createReport, header);
}
});

start.setDisable(false);

bottom.getChildren().addAll(back, HorizontalSpace.create(), clear, HorizontalSpace.create(), start);
setBottom(bottom);
}

private void createAndAddCenter(boolean useSavedState) {
IPHeader savedHeaderInternal = useSavedState ? this.savedHeader : null;

VBox center = new VBox(5);
center.setAlignment(Pos.CENTER_LEFT);
center.setPadding(new Insets(0, 0, 10, 0));
Expand Down Expand Up @@ -145,7 +190,7 @@ public void onTraverse(Node n, Bounds b) {
String[] shortIds = METSHeaderUtils.getFieldList(sipType);
AbstractGroup group = null;
for (String fieldShortId : shortIds) {
group = METSHeaderUtils.getComponentForField(sipType, fieldShortId, savedHeader);
group = METSHeaderUtils.getComponentForField(sipType, fieldShortId, savedHeaderInternal);
if (group instanceof StatusGroup) {
sectionStatus.addGroup(group);
} else if (group instanceof AltRecordGroup) {
Expand All @@ -165,50 +210,4 @@ public void onTraverse(Node n, Bounds b) {
center.getChildren().add(scrollPane);
setCenter(center);
}

private void createBottom() {
HBox bottom = new HBox();
bottom.setPadding(new Insets(0, 10, 10, 10));
bottom.setAlignment(Pos.CENTER_LEFT);

Button back = new Button(I18n.t(Constants.I18N_BACK));
back.setOnAction(actionEvent -> {
stage.setRoot(previousPanel);
stage.sizeToScene();
});

start = new Button(I18n.t(Constants.I18N_START));
start.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
IPHeader header = new IPHeader();
boolean valid = true;

for (AbstractGroup fieldGroup : fieldGroups) {

if (!fieldGroup.validate()) {
valid = false;
} else {
if (fieldGroup instanceof StatusGroup) {
((StatusGroup) fieldGroup).addStatusToHeader(header);
} else if (fieldGroup instanceof AltRecordGroup) {
((AltRecordGroup) fieldGroup).addAltRecordsToHeader(header);
} else if (fieldGroup instanceof AgentGroup) {
((AgentGroup) fieldGroup).addAgentsToHeader(header);
}
}
}

if (valid) {
ConfigurationManager.serialize(header, sipType.name() + Constants.RODAIN_SERIALIZE_FILE_METS_HEADER_SUFFIX);
stage.startCreation(outputFolder, exportAll, exportItems, sipNameBuilder, createReport, header);
}
}
});

start.setDisable(false);

bottom.getChildren().addAll(back, HorizontalSpace.create(), start);
setBottom(bottom);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ protected AbstractItem internalCreateRow(boolean usingSavedItems) {
IPAgent savedItem = savedItemIterator.next();

boolean validPredefinedType = StringUtils.isBlank(predefinedType)
|| (StringUtils.isNotBlank(predefinedType) && predefinedType.equals(savedItem.getType().toString()));
|| predefinedType.equals(savedItem.getType().toString());

boolean validPredefinedRole = StringUtils.isBlank(predefinedRole)
|| (StringUtils.isNotBlank(predefinedRole) && predefinedRole.equals(savedItem.getRole()));
boolean validPredefinedRole = StringUtils.isBlank(predefinedRole) || predefinedRole.equals(savedItem.getRole());

boolean validPredefinedOtherType = StringUtils.isBlank(predefinedOtherType)
|| (StringUtils.isNotBlank(predefinedOtherType) && predefinedOtherType.equals(savedItem.getOtherType()));
|| predefinedOtherType.equals(savedItem.getOtherType());

boolean validNameAndNote = !namesAndNotes.isEmpty()
&& namesAndNotes.contains(new NameAndNotePair(savedItem.getName(), savedItem.getNote()));
boolean validNameAndNote = namesAndNotes.isEmpty()
|| namesAndNotes.contains(new NameAndNotePair(savedItem.getName(), savedItem.getNote()));

if (validPredefinedType && validPredefinedOtherType && validPredefinedRole && validNameAndNote) {
return new AgentItem(this, i18nNameLabel, i18nNameDescription, i18nNoteLabel, i18nNoteDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ protected AbstractItem internalCreateRow(boolean usingSavedItems) {
while (savedItemIterator.hasNext()) {
IPAltRecordID savedItem = savedItemIterator.next();

boolean validPredefinedType = StringUtils.isBlank(predefinedType)
|| (StringUtils.isNotBlank(predefinedType) && predefinedType.equals(savedItem.getType()));
boolean validPredefinedType = StringUtils.isBlank(predefinedType) || predefinedType.equals(savedItem.getType());

boolean validValue = possibleValuesSet.isEmpty() || possibleValuesSet.contains(savedItem.getValue());

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/properties/lang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ remove=Remove
start=Start
rename=Rename
root=Root
clear=Clear

CreationModalPreparation.choose=Choose...
CreationModalPreparation.creatingSips=Creating SIPs
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/properties/lang_pt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ remove=Remover
start=Iniciar
rename=Renomear
root=Raiz
clear=Limpar

CreationModalPreparation.choose=Escolher...
CreationModalPreparation.creatingSips=A criar pacotes de submissão
Expand Down Expand Up @@ -273,4 +274,4 @@ ExportBox.title=4. Pacotes de Submissão

SchemaPane.tooManySelected.header=Demasiados itens seleccionados
SchemaPane.tooManySelected.content=Edição múltipla não disponível
SchemaPane.tooManySelected.title=Demasiados itens seleccionados
SchemaPane.tooManySelected.title=Demasiados itens seleccionados

0 comments on commit 069b5df

Please sign in to comment.