Skip to content

Cable edit improvements #1708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db/sql/static/populate_setting_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ description.','true'),
(23088,'ItemDomainCableDesign.List.Display.TotalReqLengthDisplay','Display total required cable length.','false'),
(23089,'ItemDomainCableDesign.List.FilterBy.TotalReqLengthDisplay','Filter for total required cable length.',NULL),
(23090,'ItemDomainCableDesign.List.Display.QrId','Display component qrId.','false'),
(23091,'ItemDomainCableDesign.Default.CablePrefix','Default cable prefix for cable design.',NULL),
(23092,'ItemDomainCableDesign.Default.Project','Default project for cable design.',NULL),
(23093,'ItemDomainCableDesign.Default.TechnicalSystem','Default technical system for cable design.',NULL),
(24000,'ItemDomainCableCatalog.List.AutoLoad.FilterBy.Properties','Automatically load component list with display properties for filtering.','true'),
(24001,'ItemDomainCableCatalog.List.Display.ItemCategory','Display catalog item category.','true'),
(24002,'ItemDomainCableCatalog.List.Display.CreatedByUser','Display created by username.','false'),
Expand Down
5 changes: 4 additions & 1 deletion db/sql/updates/updateTo3.16.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
-- Execute by running `mysql CDB_DB_NAME -h 127.0.0.1 -u cdb -p < updateTo3.16.2.sql`

INSERT IGNORE INTO `setting_type` VALUES
(23090,'ItemDomainCableDesign.List.Display.QrId','Display component qrId.','false');
(23090,'ItemDomainCableDesign.List.Display.QrId','Display component qrId.','false'),
(23091,'ItemDomainCableDesign.Default.CablePrefix','Default cable prefix for cable design.',NULL),
(23092,'ItemDomainCableDesign.Default.Project','Default project for cable design.',NULL),
(23093,'ItemDomainCableDesign.Default.TechnicalSystem','Default technical system for cable design.',NULL);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import gov.anl.aps.cdb.portal.model.ItemDomainCableDesignLazyDataModel;
import gov.anl.aps.cdb.portal.model.ItemDomainMachineDesignTreeNode;
import gov.anl.aps.cdb.portal.model.db.beans.ItemDomainCableDesignFacade;
import gov.anl.aps.cdb.portal.model.db.beans.ItemProjectFacade;
import gov.anl.aps.cdb.portal.model.db.entities.CdbEntity;
import gov.anl.aps.cdb.portal.model.db.entities.Item;
import gov.anl.aps.cdb.portal.model.db.entities.ItemCategory;
Expand All @@ -32,8 +33,10 @@
import gov.anl.aps.cdb.portal.view.objects.DomainImportExportInfo;
import gov.anl.aps.cdb.portal.view.objects.ImportExportFormatInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -57,6 +60,9 @@
@SessionScoped
public class ItemDomainCableDesignController extends ItemController<ItemDomainCableDesignControllerUtility, ItemDomainCableDesign, ItemDomainCableDesignFacade, ItemDomainCableDesignSettings, ItemDomainCableDesignLazyDataModel> {

@EJB
ItemProjectFacade itemProjectFacade;

@Override
protected ItemDomainCableDesignControllerUtility createControllerUtilityInstance() {
return new ItemDomainCableDesignControllerUtility();
Expand Down Expand Up @@ -968,10 +974,31 @@ public String prepareCreate() {
* Prepares cable wizard.
*/
public String prepareWizardCable() {
CableWizard.getInstance().reset();
CableWizard wizard = CableWizard.getInstance();
wizard.reset();
ensureSettingDefaultsLoaded();

populateEmptyDefaultWizardValues(wizard);

return "/views/itemDomainCableDesign/create?faces-redirect=true";
}

public void populateEmptyDefaultWizardValues(CableWizard wizard) {
if (wizard.getInputValueName() == null || wizard.getInputValueName().isEmpty()) {
wizard.setInputValueName(settingObject.getDefaultCablePrefix());
}

if (wizard.getSelectionProjectList() == null || wizard.getSelectionProjectList().isEmpty()) {
List<ItemProject> defaultProjectList = settingObject.getDefaultProjectList();
wizard.setSelectionProjectList(new ArrayList<>(defaultProjectList));
}

if (wizard.getSelectionTechnicalSystemList() == null || wizard.getSelectionTechnicalSystemList().isEmpty()) {
List<ItemCategory> defaultCategoryList = settingObject.getDefaultCategoryList();
wizard.setSelectionTechnicalSystemList(new ArrayList<>(defaultCategoryList));
}
}

@Override
public ItemDomainCableDesignLazyDataModel createItemLazyDataModel() {
return new ItemDomainCableDesignLazyDataModel(itemDomainCableDesignFacade, getDefaultDomain(), settingObject);
Expand Down Expand Up @@ -1168,6 +1195,75 @@ public void deleteConnection(CableDesignConnectionListObject connection) {
connectionToDelete = null;
}

public void ensureSettingDefaultsLoaded() {
ItemDomainCableDesignSettings settingObject = getSettingObject();

String namePrefix = settingObject.getDefaultCablePrefix();
if (namePrefix == null) {
settingObject.setDefaultCablePrefix("");
}

// Load default project
String defaultProject = settingObject.getDefaultProject();
List<Integer> projectIds = new ArrayList<>();
if (defaultProject != null && !defaultProject.trim().isEmpty()) {
projectIds = Arrays.stream(defaultProject.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
}
List<ItemProject> defaultProjectList = settingObject.getDefaultProjectList();
if (defaultProjectList == null) {
defaultProjectList = new ArrayList<>();
}

Iterator<ItemProject> projectIterator = defaultProjectList.iterator();
while (projectIterator.hasNext()) {
ItemProject itemProject = projectIterator.next();
Integer id = itemProject.getId();
if (projectIds.contains(id)) {
projectIds.remove(id);
} else {
projectIterator.remove();
}
}

for (Integer projectId : projectIds) {
ItemProject project = itemProjectFacade.find(projectId);
defaultProjectList.add(project);
}
settingObject.setDefaultProjectList(defaultProjectList);

// Load default category list
String defaultTechnicalSystem = settingObject.getDefaultTechnicalSystem();
List<Integer> categoryIds = new ArrayList<>();
if (defaultTechnicalSystem != null && !defaultTechnicalSystem.trim().isEmpty()) {
categoryIds = Arrays.stream(defaultTechnicalSystem.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
}
List<ItemCategory> defaultTechnicalSystemList = settingObject.getDefaultCategoryList();
if (defaultTechnicalSystemList == null) {
defaultTechnicalSystemList = new ArrayList<>();
}

Iterator<ItemCategory> categoryIterator = defaultTechnicalSystemList.iterator();
while (categoryIterator.hasNext()) {
ItemCategory itemCategory = categoryIterator.next();
Integer id = itemCategory.getId();
if (categoryIds.contains(id)) {
categoryIds.remove(id);
} else {
categoryIterator.remove();
}
}

for (Integer categoryId : categoryIds) {
ItemCategory category = itemCategoryFacade.find(categoryId);
defaultTechnicalSystemList.add(category);
}
settingObject.setDefaultCategoryList(defaultTechnicalSystemList);
}

// <editor-fold defaultstate="collapsed" desc="import/export support">
@Override
public boolean getEntityDisplayImportButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public void reset() {
selectionProjectList = null;
selectionTechnicalSystemList = null;
members.clear();
selectionCableType = null;
selectionCableType = cableTypeCatalog;
selectionCableCatalogItem = null;
cableItem = null;
portEnd1 = null;
Expand Down
Loading