use of org.candlepin.model.dto.ContentData in project candlepin by candlepin.
the class ProductManager method isChangedBy.
/**
* Determines whether or not this entity would be changed if the given DTO were applied to this
* object.
*
* @param dto
* The product DTO to check for changes
*
* @throws IllegalArgumentException
* if dto is null
*
* @return
* true if this product would be changed by the given DTO; false otherwise
*/
public static boolean isChangedBy(Product entity, ProductData dto) {
// Check simple properties first
if (dto.getId() != null && !dto.getId().equals(entity.getId())) {
return true;
}
if (dto.getName() != null && !dto.getName().equals(entity.getName())) {
return true;
}
if (dto.getMultiplier() != null && !dto.getMultiplier().equals(entity.getMultiplier())) {
return true;
}
if (dto.isLocked() != null && !dto.isLocked().equals(entity.isLocked())) {
return true;
}
Collection<String> dependentProductIds = dto.getDependentProductIds();
if (dependentProductIds != null && !Util.collectionsAreEqual(entity.getDependentProductIds(), dependentProductIds)) {
return true;
}
// Impl note:
// Depending on how strict we are regarding case-sensitivity and value-representation,
// this may get us in to trouble. We may need to iterate through the attributes, performing
// case-insensitive key/value comparison and similiarities (i.e. management_enabled: 1 is
// functionally identical to Management_Enabled: true, but it will be detected as a change
// in attributes.
Map<String, String> attributes = dto.getAttributes();
if (attributes != null && !attributes.equals(entity.getAttributes())) {
return true;
}
Collection<ProductContentData> productContent = dto.getProductContent();
if (productContent != null) {
Comparator comparator = new Comparator() {
public int compare(Object lhs, Object rhs) {
ProductContent existing = (ProductContent) lhs;
ProductContentData update = (ProductContentData) rhs;
if (existing != null && update != null) {
Content content = existing.getContent();
ContentData cdto = update.getContent();
if (content != null && cdto != null) {
if (cdto.getUuid() != null ? cdto.getUuid().equals(content.getUuid()) : (cdto.getId() != null && cdto.getId().equals(content.getId()))) {
return (update.isEnabled() != null && !update.isEnabled().equals(existing.isEnabled())) || ContentManager.isChangedBy(content, cdto) ? 1 : 0;
}
}
}
return 1;
}
};
if (!Util.collectionsAreEqual((Collection) entity.getProductContent(), (Collection) productContent, comparator)) {
return true;
}
}
return false;
}
Aggregations