protected void setupXref(Category adminInstance) { if (isDefaultCategoryLegacyMode()) { CategoryXref categoryXref = new CategoryXrefImpl(); categoryXref.setCategory(getExistingDefaultCategory(adminInstance)); categoryXref.setSubCategory(adminInstance); if (!adminInstance.getAllParentCategoryXrefs().contains(categoryXref) && categoryXref.getCategory() != null) { adminInstance.getAllParentCategoryXrefs().add(categoryXref); } } }
protected CategoryXref createXref(Tuple<Category, Category> parentAndChild) { CategoryXref xref = new CategoryXrefImpl(); xref.setCategory(parentAndChild.getFirst()); xref.setSubCategory(parentAndChild.getSecond()); return xref; }
@Override public void setParentCategory(Category category) { List<CategoryXref> xrefs = getAllParentCategoryXrefs(); boolean found = false; for (CategoryXref xref : xrefs) { if (xref.getCategory().equals(category)) { xref.setDefaultReference(true); found = true; } else if (xref.getDefaultReference() != null && xref.getDefaultReference()) { xref.setDefaultReference(null); } } if (!found && category != null) { CategoryXref xref = new CategoryXrefImpl(); xref.setSubCategory(this); xref.setCategory(category); xref.setDefaultReference(true); allParentCategoryXrefs.add(xref); } }
CategoryXref cxref1 = new CategoryXrefImpl(); cxref1.setCategory(c2); cxref1.setSubCategory(c1); c1.setAllParentCategoryXrefs(c1Parents); CategoryXref cxref2 = new CategoryXrefImpl(); cxref2.setCategory(c1); cxref2.setSubCategory(c2);
category3 = catalogService.saveCategory(category3); CategoryXref temp = new CategoryXrefImpl(); temp.setCategory(category); temp.setSubCategory(category3); category3 = catalogService.findCategoryById(cat3Id); category3.getAllParentCategoryXrefs().clear(); CategoryXref temp2 = new CategoryXrefImpl(); temp2.setCategory(category); temp2.setSubCategory(category3); category3.getAllParentCategoryXrefs().add(temp2); CategoryXref temp3 = new CategoryXrefImpl(); temp3.setCategory(category2); temp3.setSubCategory(category3);
.orElseThrow(() -> new ResourceNotFoundException("Category with ID: " + categoryId + " does not exist")); final CategoryXref parentChildCategoryXref = new CategoryXrefImpl(); parentChildCategoryXref.setCategory(parentCategory); parentChildCategoryXref.setSubCategory(hrefCategory);
@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Category adminInstance = (Category) Class.forName(entity.getType()[0]).newInstance(); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective); adminInstance = (Category) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); CategoryXref categoryXref = new CategoryXrefImpl(); categoryXref.setCategory(adminInstance.getDefaultParentCategory()); categoryXref.setSubCategory(adminInstance); if (adminInstance.getDefaultParentCategory() != null && !adminInstance.getAllParentCategoryXrefs().contains(categoryXref)) { adminInstance.getAllParentCategoryXrefs().add(categoryXref); } adminInstance = (Category) dynamicEntityDao.merge(adminInstance); return helper.getRecord(adminProperties, adminInstance, null, null); } catch (Exception e) { throw new ServiceException("Unable to add entity for " + entity.getType()[0], e); } }
@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { AdornedTargetList adornedTargetList = (AdornedTargetList) persistencePackage.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST); String targetPath = adornedTargetList.getTargetObjectPath() + "." + adornedTargetList.getTargetIdProperty(); String linkedPath = adornedTargetList.getLinkedObjectPath() + "." + adornedTargetList.getLinkedIdProperty(); Long parentId = Long.parseLong(persistencePackage.getEntity().findProperty(linkedPath).getValue()); Long childId = Long.parseLong(persistencePackage.getEntity().findProperty(targetPath).getValue()); Category parent = (Category) dynamicEntityDao.retrieve(CategoryImpl.class, parentId); Category child = (Category) dynamicEntityDao.retrieve(CategoryImpl.class, childId); CategoryXref categoryXref = new CategoryXrefImpl(); categoryXref.setSubCategory(child); categoryXref.setCategory(parent); if (parent.getAllChildCategoryXrefs().contains(categoryXref)) { throw new ServiceException("Add unsuccessful. Cannot add a duplicate child category."); } checkParents(child, parent); return helper.getCompatibleModule(OperationType.ADORNEDTARGETLIST).add(persistencePackage); }