Skip to content
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

LPS-152408 Include externalReferenceCode for Product and Product Group #671

Closed
wants to merge 8 commits into from
Expand Up @@ -38,6 +38,7 @@ dependencies {
compileOnly project(":apps:friendly-url:friendly-url-api")
compileOnly project(":apps:frontend-taglib:frontend-taglib-clay")
compileOnly project(":apps:journal:journal-api")
compileOnly project(":apps:object:object-api")
compileOnly project(":apps:portal-search:portal-search-spi")
compileOnly project(":apps:portal-vulcan:portal-vulcan-api")
compileOnly project(":apps:portal:portal-dao-orm-custom-sql-api")
Expand Down
@@ -0,0 +1,100 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.commerce.internal.object.system;

import com.liferay.commerce.product.model.CPDefinition;
import com.liferay.commerce.product.model.CPDefinitionTable;
import com.liferay.object.constants.ObjectDefinitionConstants;
import com.liferay.object.model.ObjectField;
import com.liferay.object.system.BaseSystemObjectDefinitionMetadata;
import com.liferay.object.system.SystemObjectDefinitionMetadata;
import com.liferay.petra.sql.dsl.Column;
import com.liferay.petra.sql.dsl.Table;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.osgi.service.component.annotations.Component;

/**
* @author José Abelenda
*/
@Component(enabled = true, service = SystemObjectDefinitionMetadata.class)
public class CPDefinitionEntrySystemObjectDefinitionMetadata
extends BaseSystemObjectDefinitionMetadata {

@Override
public Map<Locale, String> getLabelMap() {
return createLabelMap("cp-definition");
}

@Override
public Class<?> getModelClass() {
return CPDefinition.class;
}

@Override
public List<ObjectField> getObjectFields() {
return Arrays.asList(
createObjectField(
"Text", "String", "description", "description", false),
createObjectField(
"Text", "String", "external-reference-code",
"externalReferenceCode", false),
createObjectField("Text", "String", "name", "name", false),
createObjectField(
"Text", "String", "product-id", "productId", false),
createObjectField(
"Text", "String", "short-description", "shortDescription",
false),
createObjectField("Text", "String", "sku", "skuFormatted", false),
createObjectField(
"Text", "String", "thumbnail", "thumbnail", false),
createObjectField("Text", "String", "uuid", "uuid", false));
}

@Override
public Map<Locale, String> getPluralLabelMap() {
return createLabelMap("cp-definitions");
}

@Override
public Column<?, Long> getPrimaryKeyColumn() {
return CPDefinitionTable.INSTANCE.CPDefinitionId;
}

@Override
public String getRESTContextPath() {
return "headless-commerce-admin-catalog/v1.0/products";
}

@Override
public String getScope() {
return ObjectDefinitionConstants.SCOPE_COMPANY;
}

@Override
public Table getTable() {
return CPDefinitionTable.INSTANCE;
}

@Override
public int getVersion() {
return 1;
}

}
@@ -0,0 +1,94 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.commerce.internal.object.system;

import com.liferay.commerce.pricing.model.CommercePricingClass;
import com.liferay.commerce.pricing.model.CommercePricingClassTable;
import com.liferay.object.constants.ObjectDefinitionConstants;
import com.liferay.object.model.ObjectField;
import com.liferay.object.system.BaseSystemObjectDefinitionMetadata;
import com.liferay.object.system.SystemObjectDefinitionMetadata;
import com.liferay.petra.sql.dsl.Column;
import com.liferay.petra.sql.dsl.Table;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.osgi.service.component.annotations.Component;

/**
* @author Gleice Lisbino
*/
@Component(enabled = true, service = SystemObjectDefinitionMetadata.class)
public class CommerceProductGroupSystemObjectDefinitionMetadata
extends BaseSystemObjectDefinitionMetadata {

@Override
public Map<Locale, String> getLabelMap() {
return createLabelMap("commerce-product-group");
}

@Override
public Class<?> getModelClass() {
return CommercePricingClass.class;
}

@Override
public List<ObjectField> getObjectFields() {
return Arrays.asList(
createObjectField(
"Text", "String", "description", "description", false),
createObjectField(
"Text", "String", "external-reference-code",
"externalReferenceCode", false),
createObjectField("Text", "String", "name", "name", false),
createObjectField(
"Integer", "Integer", "number-of-products", "productsCount",
false));
}

@Override
public Map<Locale, String> getPluralLabelMap() {
return createLabelMap("commerce-product-groups");
}

@Override
public Column<?, Long> getPrimaryKeyColumn() {
return CommercePricingClassTable.INSTANCE.commercePricingClassId;
}

@Override
public String getRESTContextPath() {
return "headless-commerce-admin-catalog/v1.0/product-groups";
}

@Override
public String getScope() {
return ObjectDefinitionConstants.SCOPE_COMPANY;
}

@Override
public Table getTable() {
return CommercePricingClassTable.INSTANCE;
}

@Override
public int getVersion() {
return 1;
}

}
Expand Up @@ -104,6 +104,11 @@ public void testGetObjectDefinitionsPageWithSortString() throws Exception {
Arrays.asList(objectDefinition2, objectDefinition1),
objectDefinitions.subList(
objectDefinitions.size() - 3, objectDefinitions.size() - 1));

_objectDefinitionLocalService.deleteObjectDefinition(
objectDefinition1.getId());
_objectDefinitionLocalService.deleteObjectDefinition(
objectDefinition2.getId());
}

@Ignore
Expand Down Expand Up @@ -133,6 +138,9 @@ public void testPutObjectDefinitionWithStorageType() throws Exception {

Assert.assertEquals("BAD_REQUEST", problem.getStatus());
}

_objectDefinitionLocalService.deleteObjectDefinition(
postObjectDefinition.getId());
}

@Override
Expand Down
Expand Up @@ -380,7 +380,7 @@ public ObjectField updateCustomObjectField(
}
}
else {
_validateName(objectFieldId, objectDefinition, name);
_validateName(objectFieldId, objectDefinition, name, false);
}

_setBusinessTypeAndDBType(businessType, dbType, objectField);
Expand Down Expand Up @@ -414,7 +414,7 @@ private ObjectField _addObjectField(
_validateIndexed(
businessType, dbType, indexed, indexedAsKeyword, indexedLanguageId);
_validateLabel(labelMap);
_validateName(0, objectDefinition, name);
_validateName(0, objectDefinition, name, system);

ObjectField objectField = objectFieldPersistence.create(
counterLocalService.increment());
Expand Down Expand Up @@ -646,7 +646,8 @@ private void _validateLabel(Map<Locale, String> labelMap)
}

private void _validateName(
long objectFieldId, ObjectDefinition objectDefinition, String name)
long objectFieldId, ObjectDefinition objectDefinition, String name,
boolean system)
throws PortalException {

if (Validator.isNull(name)) {
Expand All @@ -670,7 +671,8 @@ private void _validateName(
throw new ObjectFieldNameException.MustBeLessThan41Characters();
}

if (_reservedNames.contains(StringUtil.toLowerCase(name)) ||
if ((!system &&
_reservedNames.contains(StringUtil.toLowerCase(name))) ||
StringUtil.equalsIgnoreCase(
objectDefinition.getPKObjectFieldName(), name)) {

Expand Down
Expand Up @@ -317,29 +317,6 @@ public void testAddSystemObjectField() throws Exception {

// Reserved name

String[] reservedNames = {
"actions", "companyId", "createDate", "creator", "dateCreated",
"dateModified", "externalReferenceCode", "groupId", "id",
"lastPublishDate", "modifiedDate", "statusByUserId",
"statusByUserName", "statusDate", "userId", "userName"
};

for (String reservedName : reservedNames) {
try {
_testAddSystemObjectField(
ObjectFieldUtil.createObjectField(
"Text", "String", reservedName,
_getObjectFieldSettings("Text")));

Assert.fail();
}
catch (ObjectFieldNameException objectFieldNameException) {
Assert.assertEquals(
"Reserved name " + reservedName,
objectFieldNameException.getMessage());
}
}

String objectDefinitionName = "A" + RandomTestUtil.randomString();

String pkObjectFieldName = TextFormatter.format(
Expand Down
Expand Up @@ -3451,6 +3451,8 @@ commerce-product-content-portlet-instance-configuration-name=Product Content
commerce-product-content-search-web-portlet-instance-configuration-name=Search Results
commerce-product-definition-configuration-name=Product Definition System Configuration
commerce-product-definitions-configuration-name=Products
commerce-product-group=Commerce Product Group
commerce-product-groups=Commerce Product Groups
commerce-product-option-facets-portlet-instance-configuration-name=Option Facet
commerce-product-price-range-facets-portlet-instance-configuration-name=Price Range Facet
commerce-product-publisher-web-portlet-instance-configuration-name=Product Publisher
Expand Down