<commit_before>package io.cattle.platform.api.resource;

import io.cattle.platform.api.action.ActionHandler;
import io.cattle.platform.api.auth.Policy;
import io.cattle.platform.api.utils.ApiUtils;
import io.cattle.platform.archaius.util.ArchaiusUtil;
import io.cattle.platform.engine.manager.ProcessNotFoundException;
import io.cattle.platform.engine.process.ExitReason;
import io.cattle.platform.engine.process.ProcessInstanceException;
import io.cattle.platform.object.ObjectManager;
import io.cattle.platform.object.meta.ActionDefinition;
import io.cattle.platform.object.meta.MapRelationship;
import io.cattle.platform.object.meta.ObjectMetaDataManager;
import io.cattle.platform.object.meta.Relationship;
import io.cattle.platform.object.process.ObjectProcessManager;
import io.cattle.platform.object.process.StandardProcess;
import io.cattle.platform.util.type.CollectionUtils;
import io.cattle.platform.util.type.InitializationTask;
import io.cattle.platform.util.type.NamedUtils;
import io.github.ibuildthecloud.gdapi.condition.Condition;
import io.github.ibuildthecloud.gdapi.condition.ConditionType;
import io.github.ibuildthecloud.gdapi.context.ApiContext;
import io.github.ibuildthecloud.gdapi.exception.ClientVisibleException;
import io.github.ibuildthecloud.gdapi.factory.SchemaFactory;
import io.github.ibuildthecloud.gdapi.id.IdFormatter;
import io.github.ibuildthecloud.gdapi.id.IdentityFormatter;
import io.github.ibuildthecloud.gdapi.model.Action;
import io.github.ibuildthecloud.gdapi.model.Field;
import io.github.ibuildthecloud.gdapi.model.Include;
import io.github.ibuildthecloud.gdapi.model.ListOptions;
import io.github.ibuildthecloud.gdapi.model.Resource;
import io.github.ibuildthecloud.gdapi.model.Schema;
import io.github.ibuildthecloud.gdapi.model.Schema.Method;
import io.github.ibuildthecloud.gdapi.request.ApiRequest;
import io.github.ibuildthecloud.gdapi.request.resource.ResourceManager;
import io.github.ibuildthecloud.gdapi.request.resource.impl.AbstractBaseResourceManager;
import io.github.ibuildthecloud.gdapi.url.UrlBuilder;
import io.github.ibuildthecloud.gdapi.util.ResponseCodes;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.ObjectUtils;

import com.netflix.config.DynamicIntProperty;

public abstract class AbstractObjectResourceManager extends AbstractBaseResourceManager implements InitializationTask {

//    private static final Logger log = LoggerFactory.getLogger(AbstractObjectResourceManager.class);

    public static final String SCHEDULE_UPDATE = "scheduleUpdate";

    private static final DynamicIntProperty REMOVE_DELAY = ArchaiusUtil.getInt("api.show.removed.for.seconds");
    private static final IdFormatter IDENTITY_FORMATTER = new IdentityFormatter();

    ObjectManager objectManager;
    ObjectProcessManager objectProcessManager;
    ObjectMetaDataManager metaDataManager;
    Map<String,ActionHandler> actionHandlersMap;
    List<ActionHandler> actionHandlers;

    @Override
    protected Object authorize(Object object) {
        return ApiUtils.authorize(object);
    }

    @Override
    protected Object createInternal(String type, ApiRequest request) {
        Class<?> clz = getClassForType(request.getSchemaFactory(), type);
        if ( clz == null ) {
            return null;
        }

        return doCreate(type, clz, CollectionUtils.toMap(request.getRequestObject()));
    }

    @SuppressWarnings("unchecked")
    protected <T> T doCreate(String type, Class<T> clz, Map<Object,Object> data) {
        Map<String,Object> properties = getObjectManager().convertToPropertiesFor(clz, data);
        if ( ! properties.containsKey(ObjectMetaDataManager.KIND_FIELD) ) {
            properties.put(ObjectMetaDataManager.KIND_FIELD, type);
        }

        Object result = objectManager.create(clz, properties);
        try {
            scheduleProcess(StandardProcess.CREATE, result, properties);
            result = objectManager.reload(result);
        } catch ( ProcessNotFoundException e ) {
        }

        return (T)result;
    }

    protected Class<?> getClassForType(SchemaFactory schemaFactory, String type) {
        Class<?> clz = schemaFactory.getSchemaClass(type);
        if ( clz == null ) {
            Schema schema = schemaFactory.getSchema(type);
            if ( schema.getParent() != null ) {
                return getClassForType(schemaFactory, schema.getParent());
            }
        }

        return clz;
    }

    @Override
    protected Object deleteInternal(String type, String id, Object obj, ApiRequest request) {<commit_msg>[api] check for missing type<commit_after>package io.cattle.platform.api.resource;

import io.cattle.platform.api.action.ActionHandler;
import io.cattle.platform.api.auth.Policy;
import io.cattle.platform.api.utils.ApiUtils;
import io.cattle.platform.archaius.util.ArchaiusUtil;
import io.cattle.platform.engine.manager.ProcessNotFoundException;
import io.cattle.platform.engine.process.ExitReason;
import io.cattle.platform.engine.process.ProcessInstanceException;
import io.cattle.platform.object.ObjectManager;
import io.cattle.platform.object.meta.ActionDefinition;
import io.cattle.platform.object.meta.MapRelationship;
import io.cattle.platform.object.meta.ObjectMetaDataManager;
import io.cattle.platform.object.meta.Relationship;
import io.cattle.platform.object.process.ObjectProcessManager;
import io.cattle.platform.object.process.StandardProcess;
import io.cattle.platform.util.type.CollectionUtils;
import io.cattle.platform.util.type.InitializationTask;
import io.cattle.platform.util.type.NamedUtils;
import io.github.ibuildthecloud.gdapi.condition.Condition;
import io.github.ibuildthecloud.gdapi.condition.ConditionType;
import io.github.ibuildthecloud.gdapi.context.ApiContext;
import io.github.ibuildthecloud.gdapi.exception.ClientVisibleException;
import io.github.ibuildthecloud.gdapi.factory.SchemaFactory;
import io.github.ibuildthecloud.gdapi.id.IdFormatter;
import io.github.ibuildthecloud.gdapi.id.IdentityFormatter;
import io.github.ibuildthecloud.gdapi.model.Action;
import io.github.ibuildthecloud.gdapi.model.Field;
import io.github.ibuildthecloud.gdapi.model.Include;
import io.github.ibuildthecloud.gdapi.model.ListOptions;
import io.github.ibuildthecloud.gdapi.model.Resource;
import io.github.ibuildthecloud.gdapi.model.Schema;
import io.github.ibuildthecloud.gdapi.model.Schema.Method;
import io.github.ibuildthecloud.gdapi.request.ApiRequest;
import io.github.ibuildthecloud.gdapi.request.resource.ResourceManager;
import io.github.ibuildthecloud.gdapi.request.resource.impl.AbstractBaseResourceManager;
import io.github.ibuildthecloud.gdapi.url.UrlBuilder;
import io.github.ibuildthecloud.gdapi.util.ResponseCodes;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.ObjectUtils;

import com.netflix.config.DynamicIntProperty;

public abstract class AbstractObjectResourceManager extends AbstractBaseResourceManager implements InitializationTask {

//    private static final Logger log = LoggerFactory.getLogger(AbstractObjectResourceManager.class);

    public static final String SCHEDULE_UPDATE = "scheduleUpdate";

    private static final DynamicIntProperty REMOVE_DELAY = ArchaiusUtil.getInt("api.show.removed.for.seconds");
    private static final IdFormatter IDENTITY_FORMATTER = new IdentityFormatter();

    ObjectManager objectManager;
    ObjectProcessManager objectProcessManager;
    ObjectMetaDataManager metaDataManager;
    Map<String,ActionHandler> actionHandlersMap;
    List<ActionHandler> actionHandlers;

    @Override
    protected Object authorize(Object object) {
        return ApiUtils.authorize(object);
    }

    @Override
    protected Object createInternal(String type, ApiRequest request) {
        Class<?> clz = getClassForType(request.getSchemaFactory(), type);
        if ( clz == null ) {
            return null;
        }

        return doCreate(type, clz, CollectionUtils.toMap(request.getRequestObject()));
    }

    @SuppressWarnings("unchecked")
    protected <T> T doCreate(String type, Class<T> clz, Map<Object,Object> data) {
        Map<String,Object> properties = getObjectManager().convertToPropertiesFor(clz, data);
        if ( ! properties.containsKey(ObjectMetaDataManager.KIND_FIELD) ) {
            properties.put(ObjectMetaDataManager.KIND_FIELD, type);
        }

        Object result = objectManager.create(clz, properties);
        try {
            scheduleProcess(StandardProcess.CREATE, result, properties);
            result = objectManager.reload(result);
        } catch ( ProcessNotFoundException e ) {
        }

        return (T)result;
    }

    protected Class<?> getClassForType(SchemaFactory schemaFactory, String type) {
        Class<?> clz = schemaFactory.getSchemaClass(type);
        if ( clz == null ) {
            Schema schema = schemaFactory.getSchema(type);
            if ( schema != null && schema.getParent() != null ) {
                return getClassForType(schemaFactory, schema.getParent());
            }
        }

        return clz;
    }

    @Override
    protected Object deleteInternal(String type, String id, Object obj, ApiRequest request) {
{'fraction_non_alphanumeric': 0.09775794283285517, 'fraction_numerical': 0.00021251726702794602, 'mean_word_length': 4.533215755437977, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567320', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2667, 'n_words': 460}