Best pattern to solve problem where objects only differ in one attribute

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables with a key-value appearance.

E.g.
___________|________
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

There are multiple tables, where this approach fits the requirement in an optimal way. Values and description are stored in enums.

Now, I have to face the situation, that there should be more than one column with values. E.g.:

___________|________|________|_____
Description 1 | Value1 1 | Value2 1 |…
Description 2 | Value1 2 | Value2 1 |…
Description 3 | Value1 3 | Value2 1 |…

For the columns applies that they are all similar. The only difference they have is in an SQL, where the value is requested.

E.g. Value1 1 SELECT * FROM ZOO WHERE […] AND LOCATION = ‘CA’

Value2 1 SELECT * FROM ZOO WHERE […] AND LOCATION = ‘UA’

This value is/was constant in the enum and seems to be the breakpoint, breaking this hard-wired construct.

One approach would be to create the same objects in the enum again with passing the location as additional parameter. This way would result in having:

Enum Values(
– Value1 1_CA
– Value2 1_UA
)

Which seems to create a big overhead, since the objects only differ in location, but all other parameters are the same.

Another way I thougt of was refactoring the enum to an abstract class and derive from it, so that I have the base values and only objects/class like following

  • CA extends BaseClass
  • UA extends BaseClass

However this seems not like a clean approach, more like an “make it any case works” approach. Inheritance would be used in the way it shouldn’t be, so I thought of delegation. But for delegation, the BaseClass must be instantiable (which is incorrect too).

How could this problem be solved without breaking the concept of clean OOP?

Add custom address attribute to checkout

I create custom address attribute, same as suggested here: https://codeblog.experius.nl/magento-2-add-extra-billing-or-shipping-field-to-the-checkout/

But when I’m place order there is error occurs:

Property "Example" does not have accessor method "getExample" in class "Magento\Quote\Api\Data\AddressExtensionInterface". 

I know that this accessor must be in generated/code folder but it’s empty there, I don’t understand why its not creating after I run di:compile. All other modules creating well.

This code must create it as well:

<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">     <extension_attributes for="Magento\Customer\Api\Data\AddressInterface">         <attribute code="example" type="string"/>     </extension_attributes> </config> 

Can you help please?

Many identical version differing by lang= attribute

I have a list of 8115 languages.

Is it a good idea to submit 8115 versions (differing by lang= attributes) of my site to Google? In the future they are to be filled by content in different languages, but for now they differ only in lang= and also "supplementary" labels (such as names of menu items) only for English and Russian.

What will Google do if it sees 8115 versions differing mainly in lang=? Will it penalize me?

How to anonymise a numeric data attribute, whilst preserving indexability?

I would like to (1-way) anonymise some bounded, numeric data attributes (e.g. age, optimistically bounded by 0 and 200), whilst still retaining the ability to use the resulting data in an index for database queries such as X < 50 or X BETWEEN 18 AND 30.

Ideally the anonymisation process would create a new set of values that were ordered but “differently” distributed, such that it is difficult to infer the old attribute values from the anonymised values.

Are there any standard algorithms that provide this capability?


My own thoughts are that I could create a function F, such that anonymisation is X -> F(X).

When a data record is saved, the relevant attribute values are transformed (the attribute name would be hashed or similarly anonymised). Query conditions based on the attribute name could then be transformed to query against the revised attribute name and the transformed query values.

I.e. X in [ 1, 2, 10, 50 ] becomes Hash(X) in [ F(1), F(2), F(10), F(50) ]

So F must satisfy:

  • X == Y implies F(X) == F(Y)

  • X < Y implies F(X) < F(Y)

  • X -> F(X) must be fast to compute

With this in mind, F could consist of multiple polynomial functions F1, F2, … Fn, each covering a sub-range of the bounded range of X, such that at the boundary Xn, Fn(Xn) == F(n+1)(Xn), such that the distribution of F(X) values is sufficiently different from the distribution of X.

The set Fn would be randomly generated and managed by the “database” layer when the bounded set of values is declared to the database (optionally with sub-range boundaries also declared), and then is transparently applied when data is saved or queries executed.

For a bounded set of positive values (like age above), polynomials with positive coefficients would work (subject to the subrange boundary conditions); for bounded sets that include negative values, polynomials comprising a series of odd powers are required along with positive coefficients.

Where the bounded set of values will be completely covered by the data set (age is again a good example, if the population is large), then the sub-ranges can be reduced to a single value (i.e a different polynomial is used for each integer age).


Clearly a significant issue is to determine what “differently distributed” or “sufficiently different” mean, given the requirement for ordered outputs to F.

Are there any standard approaches to this problem that meet the orderedness and distribution changes that I require?

How can i get the value of two attribute

How can i get the value of two attribute and put it in another attribute. I have a multiple calendar table and i want to combine all attribute in another attribute. Is it possible or not? Just experimenting. Here’s a sample code of the * HTML *

<div class="day_num" data-date="17" full-date="July&nbsp;2019"><div full-date="July 2019"></div>17</div> 

I want to put the data-date and full-date attribute to this div attribute:

<div full-date=""></div> 

Is this possible? sorry for such experimenting such thing.

CKeditor stripping allowed style attribute

I’ve installed Colorbutton to my Drupal 8 site.

I have enabled the button for Full HTML and For Basic HTML

I have allowed the attribute <span style> in the Basic HTML allowed attributes area.

I have defined a set of hex value colors.

When I edit a page the button appears and I can change font colors in the editor correctly, however, saving the page strips the attributes leaving only clean <span> tags…

what else am I suppose to do?

Magento 2 Color Attribute: How to make the size of uploaded swatches match the default ones?

For our site’s color attribute, we would like to use both the default color options and a few uploaded swatches. However, the uploaded swatches are showing up much smaller, with a white border around them that the default colors don’t have. I have tried using different sized images but it didn’t help.

The attribute is just for search results navigation on the sidebar, it is not part of a configurable product or anything complex. I’m hoping this can be solved without coding because I’m not the programmer.

Thanks!

magento 1 | how get product attribute data

Sorry for my English.

Hello. I have this code.

 $  productCollection = Mage::getModel('catalog/product')         ->getCollection()         ->addAttributeToFilter('attribute_set_id',array(12,4))         ->joinField(             'qty',             'cataloginventory/stock_item',             'qty',             'product_id=entity_id',             '{{table}}.stock_id=1',             'left'         )         ->addAttributeToFilter('qty', array("gt" => 0))         ->setPageSize(500)         ->load();      var_dump($  productCollection->getData()); 

i need get a product name , and i use this ->addAttributeToSelect('name') on my collection, but i collection don’t return me data.

in attribute settings i have this

enter image description here

How can I get all the product data in general?