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

com.sap.cloud.mt.subscription.Tools Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
/******************************************************************************
 * © 2020 SAP SE or an SAP affiliate company. All rights reserved.            *
 ******************************************************************************/

package com.sap.cloud.mt.subscription;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sap.cloud.mt.subscription.exceptions.ParameterError;

public class Tools {
    //used by sidecar for model
    private static final String TENANT_MODEL_PREFIX = "TENANT-";
    //used by sidecar for model timestamps
    private static final String TENANT_MODEL_TIMESTAMPS = "__META__";
    //used by mt-lib to have an empty schema used during start for JPA
    private static final String DUMMY_TENANT = "DUMMY_TENANT";
    public final static String SECURE_CHARS = "^[_a-zA-Z0-9\\-]+$";
    private static final ObjectMapper objectMapper=new ObjectMapper();

    public static boolean isTechnicalContainer(String tenantId) {
        // for future use to enable JPA (during application start a schema is needed)
        if (tenantId.equals(DUMMY_TENANT)) return true;
        // stores models for tenant (sidecar)
        if (tenantId.startsWith(TENANT_MODEL_PREFIX)) return true;
        // sidecar timestamps
        if (tenantId.equals(TENANT_MODEL_TIMESTAMPS)) return true;
        return false;
    }
    public static void checkTenantId(String tenantId) throws ParameterError {
        if (Tools.isTechnicalContainer(tenantId)) throw new ParameterError("Tenant Id is identical to a technical container");
        if (!tenantId.matches(SECURE_CHARS)) {
            throw new ParameterError("Tenant id contains forbidden characters");
        }
    }

    public static ObjectMapper getObjectMapper() {
        return objectMapper;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy