All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.object.system.SystemObjectDefinitionManager Maven / Gradle / Ivy

There is a newer version: 93.0.0
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2000 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.object.system;

import com.liferay.object.model.ObjectAction;
import com.liferay.object.model.ObjectDefinition;
import com.liferay.object.model.ObjectField;
import com.liferay.object.relationship.util.ObjectRelationshipUtil;
import com.liferay.petra.sql.dsl.Column;
import com.liferay.petra.sql.dsl.Table;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.model.BaseModel;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.search.Sort;
import com.liferay.portal.kernel.search.filter.Filter;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.vulcan.pagination.Page;
import com.liferay.portal.vulcan.pagination.Pagination;
import com.liferay.portal.vulcan.util.ObjectMapperUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
 * @author Marco Leo
 * @author Brian Wing Shun Chan
 */
public interface SystemObjectDefinitionManager {

	public long addBaseModel(User user, Map values)
		throws Exception;

	public BaseModel deleteBaseModel(BaseModel baseModel)
		throws PortalException;

	public BaseModel fetchBaseModelByExternalReferenceCode(
		String externalReferenceCode, long companyId);

	public default Set getAllowedObjectRelationshipTypes() {
		return ObjectRelationshipUtil.getDefaultObjectRelationshipTypes();
	}

	public BaseModel getBaseModelByExternalReferenceCode(
			String externalReferenceCode, long companyId)
		throws PortalException;

	public String getBaseModelExternalReferenceCode(long primaryKey)
		throws PortalException;

	public String getExternalReferenceCode();

	public JaxRsApplicationDescriptor getJaxRsApplicationDescriptor();

	public default Map getLabelKeys() {
		return Collections.emptyMap();
	}

	public Map getLabelMap();

	public Class getModelClass();

	public String getModelClassName();

	public String getName();

	public default List getObjectActions() {
		return new ArrayList<>();
	}

	public List getObjectFields();

	public default Page getPage(
			User user, String search, Filter filter, Pagination pagination,
			Sort[] sorts)
		throws Exception {

		return null;
	}

	public Map getPluralLabelMap();

	public Column getPrimaryKeyColumn();

	public String getRESTDTOIdPropertyName();

	public String getScope();

	public Table getTable();

	public String getTitleObjectFieldName();

	public default Map getVariables(
		String contentType, ObjectDefinition objectDefinition,
		boolean oldValues, JSONObject payloadJSONObject) {

		Class modelClass = getModelClass();

		Object object = payloadJSONObject.get(
			"model" + modelClass.getSimpleName());

		if (oldValues) {
			object = payloadJSONObject.get(
				"original" + modelClass.getSimpleName());
		}

		if (object == null) {
			object = payloadJSONObject.get(
				StringUtil.lowerCaseFirstLetter(objectDefinition.getName()));
		}

		if (object == null) {
			return null;
		}

		Map variables = new HashMap<>();

		if (object instanceof JSONObject) {
			Map map = ObjectMapperUtil.readValue(
				Map.class, object);

			Map jsonObjectMap = (Map)map.get(
				"_jsonObject");

			variables.putAll((Map)jsonObjectMap.get("map"));
		}
		else if (object instanceof Map) {
			variables.putAll((Map)object);
		}

		Map map = (Map)payloadJSONObject.get(
			"modelDTO" + contentType);

		if (oldValues) {
			map = (Map)payloadJSONObject.get(
				"originalDTO" + contentType);
		}

		if (map != null) {
			variables.putAll(map);
		}

		Map extendedProperties =
			(Map)payloadJSONObject.get("extendedProperties");

		if (extendedProperties != null) {
			variables.putAll(extendedProperties);
		}

		variables.computeIfAbsent("id", id -> payloadJSONObject.get("classPK"));

		return variables;
	}

	public int getVersion();

	public void updateBaseModel(
			long primaryKey, User user, Map values)
		throws Exception;

	public long upsertBaseModel(
			String externalReferenceCode, long companyId, User user,
			Map values)
		throws Exception;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy