/** * Creates a new instance of this class containing all property types except the one with given ID. * @param propertyId ID of the property to delete * @return new instance */ public PropertyTypes without(String propertyId) { List<PropertyType> newPropertyTypes = allPropertyTypes.stream() .filter(property -> property.getItemId().equals(propertyId)) .collect(Collectors.toList()); return new PropertyTypes(newPropertyTypes); }
/** * Creates a new instance of this class containing all property types except the one with given ID. * @param propertyId ID of the property to delete * @return new instance */ public PropertyTypes without(String propertyId) { List<PropertyType> newPropertyTypes = allPropertyTypes.stream() .filter(property -> property.getItemId().equals(propertyId)) .collect(Collectors.toList()); return new PropertyTypes(newPropertyTypes); }
/** * Creates a new instance of this class containing given property types. * If property types with the same ID existed before, they will be replaced by the new ones. * @param newProperties list of property types to change * @return new instance */ public PropertyTypes with(List<PropertyType> newProperties) { Map<String, PropertyType> updatedProperties = new HashMap<>(); for (PropertyType property : newProperties) { if (propertyTypesById.containsKey(property.getItemId())) { updatedProperties.put(property.getItemId(), property); } } List<PropertyType> newPropertyTypes = Stream.concat( allPropertyTypes.stream().map(property -> updatedProperties.getOrDefault(property.getItemId(), property)), newProperties.stream().filter(property -> !propertyTypesById.containsKey(property.getItemId())) ).collect(Collectors.toList()); return new PropertyTypes(newPropertyTypes); }
/** * Creates a new instance of this class containing given property types. * If property types with the same ID existed before, they will be replaced by the new ones. * @param newProperties list of property types to change * @return new instance */ public PropertyTypes with(List<PropertyType> newProperties) { Map<String, PropertyType> updatedProperties = new HashMap<>(); for (PropertyType property : newProperties) { if (propertyTypesById.containsKey(property.getItemId())) { updatedProperties.put(property.getItemId(), property); } } List<PropertyType> newPropertyTypes = Stream.concat( allPropertyTypes.stream().map(property -> updatedProperties.getOrDefault(property.getItemId(), property)), newProperties.stream().filter(property -> !propertyTypesById.containsKey(property.getItemId())) ).collect(Collectors.toList()); return new PropertyTypes(newPropertyTypes); }
public PropertyTypes(List<PropertyType> allPropertyTypes) { this.allPropertyTypes = new ArrayList<>(allPropertyTypes); propertyTypesById = new HashMap<>(); propertyTypesByTags = new HashMap<>(); propertyTypesBySystemTags = new HashMap<>(); propertyTypesByTarget = new HashMap<>(); for (PropertyType propertyType : allPropertyTypes) { propertyTypesById.put(propertyType.getItemId(), propertyType); for (String propertyTypeTag : propertyType.getMetadata().getTags()) { updateListMap(propertyTypesByTags, propertyType, propertyTypeTag); } for (String propertyTypeSystemTag : propertyType.getMetadata().getSystemTags()) { updateListMap(propertyTypesBySystemTags, propertyType, propertyTypeSystemTag); } updateListMap(propertyTypesByTarget, propertyType, propertyType.getTarget()); } }
public PropertyTypes(List<PropertyType> allPropertyTypes) { this.allPropertyTypes = new ArrayList<>(allPropertyTypes); propertyTypesById = new HashMap<>(); propertyTypesByTags = new HashMap<>(); propertyTypesBySystemTags = new HashMap<>(); propertyTypesByTarget = new HashMap<>(); for (PropertyType propertyType : allPropertyTypes) { propertyTypesById.put(propertyType.getItemId(), propertyType); for (String propertyTypeTag : propertyType.getMetadata().getTags()) { updateListMap(propertyTypesByTags, propertyType, propertyTypeTag); } for (String propertyTypeSystemTag : propertyType.getMetadata().getSystemTags()) { updateListMap(propertyTypesBySystemTags, propertyType, propertyTypeSystemTag); } updateListMap(propertyTypesByTarget, propertyType, propertyType.getTarget()); } }
} else { if (propertyType.getValueTypeId() == null) { logger.error("No value type id found for property type " + propertyType.getItemId());
@Override public boolean setPropertyType(PropertyType property) { PropertyType previousProperty = persistenceService.load(property.getItemId(), PropertyType.class); boolean result = false; if (previousProperty == null) { result = persistenceService.save(property); propertyTypes = propertyTypes.with(property); } else if (merge(previousProperty, property)) { result = persistenceService.save(previousProperty); propertyTypes = propertyTypes.with(previousProperty); } return result; }
@Override public boolean setPropertyType(PropertyType property) { PropertyType previousProperty = persistenceService.load(property.getItemId(), PropertyType.class); boolean result = false; if (previousProperty == null) { result = persistenceService.save(property); propertyTypes = propertyTypes.with(property); } else if (merge(previousProperty, property)) { result = persistenceService.save(previousProperty); propertyTypes = propertyTypes.with(previousProperty); } return result; }