<commit_before>/*
 * Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.
 */

package com.haulmont.cuba.core.sys.restapi;

import com.haulmont.cuba.core.global.EntityLoadInfo;
import com.haulmont.cuba.core.global.UuidProvider;

import java.util.*;

/**
 * Author: <NAME>
 * Date: 27.04.2011
 * Time: 0:55:10
 */
public class CommitRequest {
    private Collection commitInstances;
    private Collection removeInstances;
    private boolean softDeletion;
    private HashSet<String> newInstanceIds = new HashSet<String>();
    private Map<String, InstanceRef> instanceRefs = new HashMap<String, InstanceRef>();

    public Collection getCommitInstances() {
        return commitInstances == null ? Collections.emptyList() : commitInstances;
    }

    public Collection getRemoveInstances() {
        return removeInstances == null ? Collections.emptyList() : removeInstances;
    }


    public boolean isSoftDeletion() {
        return softDeletion;
    }

    public void setCommitInstances(Collection commitInstances) {
        this.commitInstances = commitInstances;
    }

    public void setRemoveInstances(Collection removeInstances) {
        this.removeInstances = removeInstances;
    }

    public void setSoftDeletion(boolean softDeletion) {
        this.softDeletion = softDeletion;
    }

    public Collection getNewInstanceIds() {
        return Collections.unmodifiableSet(newInstanceIds);
    }

    public InstanceRef parseInstanceRefAndRegister(String id) throws InstantiationException, IllegalAccessException {
        boolean isNew = false;
        if (id.startsWith("NEW-")) {
            id = id.substring("NEW-".length());
            isNew = true;
        }

        InstanceRef existingRef = instanceRefs.get(id);
        if (existingRef != null) {
            return existingRef;
        }

        EntityLoadInfo loadInfo = EntityLoadInfo.parse(id);
        if (loadInfo == null) {
            if (isNew) {
                UUID uuid = UuidProvider.createUuid();
                id = id + "-" + uuid;
                loadInfo = EntityLoadInfo.parse(id);
                if (loadInfo == null) {
                    throw new RuntimeException("Cannot parse id: " + id);
                }
            } else
                throw new RuntimeException("Cannot parse id: " + id);
        }

        if (isNew)
            newInstanceIds.add(id);

        InstanceRef result = new InstanceRef(loadInfo);
        instanceRefs.put(id, result);
        return result;
    }
}
<commit_msg>REST-API: soft deletion by default<commit_after>/*
 * Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.
 */

package com.haulmont.cuba.core.sys.restapi;

import com.haulmont.cuba.core.global.EntityLoadInfo;
import com.haulmont.cuba.core.global.UuidProvider;

import java.util.*;

/**
 * Author: <NAME>
 * Date: 27.04.2011
 * Time: 0:55:10
 * $Id$
 */
public class CommitRequest {
    private Collection commitInstances;
    private Collection removeInstances;
    private boolean softDeletion = true;
    private HashSet<String> newInstanceIds = new HashSet<String>();
    private Map<String, InstanceRef> instanceRefs = new HashMap<String, InstanceRef>();

    public Collection getCommitInstances() {
        return commitInstances == null ? Collections.emptyList() : commitInstances;
    }

    public Collection getRemoveInstances() {
        return removeInstances == null ? Collections.emptyList() : removeInstances;
    }

    public boolean isSoftDeletion() {
        return softDeletion;
    }

    public void setCommitInstances(Collection commitInstances) {
        this.commitInstances = commitInstances;
    }

    public void setRemoveInstances(Collection removeInstances) {
        this.removeInstances = removeInstances;
    }

    public void setSoftDeletion(boolean softDeletion) {
        this.softDeletion = softDeletion;
    }

    public Collection getNewInstanceIds() {
        return Collections.unmodifiableSet(newInstanceIds);
    }

    public InstanceRef parseInstanceRefAndRegister(String id) throws InstantiationException, IllegalAccessException {
        boolean isNew = false;
        if (id.startsWith("NEW-")) {
            id = id.substring("NEW-".length());
            isNew = true;
        }

        InstanceRef existingRef = instanceRefs.get(id);
        if (existingRef != null) {
            return existingRef;
        }

        EntityLoadInfo loadInfo = EntityLoadInfo.parse(id);
        if (loadInfo == null) {
            if (isNew) {
                UUID uuid = UuidProvider.createUuid();
                id = id + "-" + uuid;
                loadInfo = EntityLoadInfo.parse(id);
                if (loadInfo == null) {
                    throw new RuntimeException("Cannot parse id: " + id);
                }
            } else
                throw new RuntimeException("Cannot parse id: " + id);
        }

        if (isNew)
            newInstanceIds.add(id);

        InstanceRef result = new InstanceRef(loadInfo);
        instanceRefs.put(id, result);
        return result;
    }
}

{'fraction_non_alphanumeric': 0.09172960029471358, 'fraction_numerical': 0.006262663473936269, 'mean_word_length': 2.267148014440433, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5397202', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1412, 'n_words': 346}