com.liferay.commerce.internal.object.validation.rule.BasePermissionObjectValidationRuleEngineImpl Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.commerce.internal.object.validation.rule;
import com.liferay.object.scope.ObjectDefinitionScoped;
import com.liferay.object.validation.rule.ObjectValidationRuleEngine;
import com.liferay.petra.string.StringBundler;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.TextFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
/**
* @author Crescenzo Rega
*/
public abstract class BasePermissionObjectValidationRuleEngineImpl
implements ObjectDefinitionScoped, ObjectValidationRuleEngine {
@Override
public Map execute(
Map inputObjects, String script) {
return HashMapBuilder.put(
"validationCriteriaMet",
() -> hasValidationCriteriaMet(inputObjects)
).build();
}
@Override
public List getAllowedObjectDefinitionNames() {
return Arrays.asList(getObjectDefinitionName());
}
@Override
public String getKey() {
return StringBundler.concat(
"javaDelegate#", getObjectDefinitionName(), "#permission");
}
@Override
public String getLabel(Locale locale) {
return LanguageUtil.get(
locale,
TextFormatter.format(
getObjectDefinitionName() + "-permission", TextFormatter.K));
}
protected boolean equals(
Map map1, Map map2, String... keys) {
for (String key : keys) {
if (!Objects.equals(map1.get(key), map2.get(key))) {
return false;
}
}
return true;
}
protected abstract String getObjectDefinitionName();
protected abstract boolean hasValidationCriteriaMet(
Map inputObjects)
throws Exception;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy