<commit_before>package ai.ilikeplaces.logic.crud.unit;

import ai.ilikeplaces.doc.EXPECTNULL;
import ai.ilikeplaces.doc.FORGETNULL;
import ai.ilikeplaces.doc.License;
import ai.ilikeplaces.doc.NOTE;
import ai.ilikeplaces.entities.HumansPrivateEvent;
import ai.ilikeplaces.entities.PrivateEvent;
import ai.ilikeplaces.exception.NoPrivilegesException;
import ai.ilikeplaces.jpa.CrudServiceLocal;
import ai.ilikeplaces.rbs.RBGet;
import ai.ilikeplaces.util.AbstractSLBCallbacks;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

/**
 * Created by IntelliJ IDEA.
 * User: <a href="http://www.ilikeplaces.com"> http://www.ilikeplaces.com </a>
 * Date: Jan 14, 2010
 * Time: 11:53:11 PM
 */
@License(content = "This code is licensed under GNU AFFERO GENERAL PUBLIC LICENSE Version 3")
@Stateless
public class DPrivateEvent extends AbstractSLBCallbacks implements DPrivateEventLocal {

    @EJB
    private CrudServiceLocal<PrivateEvent> privateEventCrudServiceLocal_;


    @EJB
    private CrudServiceLocal<HumansPrivateEvent> humansPrivateEventCrudServiceLocal;
    
    private static final String DELETE_THIS_EVENT = "delete this event.";

    @Override
    @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
    public boolean doNTxDPrivateEvent(final String humanId, final long privateEventId) throws NoPrivilegesException {

        boolean returnVal = false;

        checkIfOwner:
        {
            @FORGETNULL
            final HumansPrivateEvent humansPrivateEvent = humansPrivateEventCrudServiceLocal.find(HumansPrivateEvent.class, humanId);

            @EXPECTNULL
            final PrivateEvent privateEvent = privateEventCrudServiceLocal_.find(PrivateEvent.class, privateEventId);

            if (privateEvent.getPrivateEventOwners().contains(humansPrivateEvent)) {
                privateEventCrudServiceLocal_.delete(PrivateEvent.class, privateEvent.getPrivateEventId());
                returnVal = true;
            } else {
                throw new NoPrivilegesException(humanId, DELETE_THIS_EVENT);
            }
        }
        return returnVal;
    }
}<commit_msg>[feature #21293885] Only the last owner to delete a private event should delete the event itself, if not just remove the owner from the event DONE<commit_after>package ai.ilikeplaces.logic.crud.unit;

import ai.ilikeplaces.doc.EXPECTNULL;
import ai.ilikeplaces.doc.FORGETNULL;
import ai.ilikeplaces.doc.License;
import ai.ilikeplaces.doc.NOTE;
import ai.ilikeplaces.entities.HumansPrivateEvent;
import ai.ilikeplaces.entities.PrivateEvent;
import ai.ilikeplaces.exception.NoPrivilegesException;
import ai.ilikeplaces.jpa.CrudServiceLocal;
import ai.ilikeplaces.rbs.RBGet;
import ai.ilikeplaces.util.AbstractSLBCallbacks;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: <a href="http://www.ilikeplaces.com"> http://www.ilikeplaces.com </a>
 * Date: Jan 14, 2010
 * Time: 11:53:11 PM
 */
@License(content = "This code is licensed under GNU AFFERO GENERAL PUBLIC LICENSE Version 3")
@Stateless
public class DPrivateEvent extends AbstractSLBCallbacks implements DPrivateEventLocal {

    @EJB
    private CrudServiceLocal<PrivateEvent> privateEventCrudServiceLocal_;


    @EJB
    private CrudServiceLocal<HumansPrivateEvent> humansPrivateEventCrudServiceLocal;

    private static final String DELETE_THIS_EVENT = "delete this event.";

    @Override
    @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
    public boolean doNTxDPrivateEvent(final String humanId, final long privateEventId) throws NoPrivilegesException {

        boolean returnVal = false;

        checkIfOwner:
        {
            @FORGETNULL
            final HumansPrivateEvent humansPrivateEvent = humansPrivateEventCrudServiceLocal.find(HumansPrivateEvent.class, humanId);

            @EXPECTNULL
            final PrivateEvent privateEvent = privateEventCrudServiceLocal_.find(PrivateEvent.class, privateEventId);

            final List<HumansPrivateEvent> privateEventOwners = privateEvent.getPrivateEventOwners();

            if (privateEventOwners.contains(humansPrivateEvent)) {
                if (privateEventOwners.size() == 1) {
                    privateEventCrudServiceLocal_.delete(PrivateEvent.class, privateEvent.getPrivateEventId());
                    returnVal = true;
                } else {
                    privateEventOwners.remove(humansPrivateEvent);

                    final List<HumansPrivateEvent> privateEventViewers = privateEvent.getPrivateEventViewers();
                    if (privateEventViewers.contains(humansPrivateEvent)) {
                        privateEventViewers.remove(humansPrivateEvent);
                    }

                    final List<HumansPrivateEvent> privateEventInvites = privateEvent.getPrivateEventInvites();
                    if (privateEventInvites.contains(humansPrivateEvent)) {
                        privateEventInvites.remove(humansPrivateEvent);
                    }
                }
            } else {
                throw new NoPrivilegesException(humanId, DELETE_THIS_EVENT);
            }
        }
        return returnVal;
    }
}
{'fraction_non_alphanumeric': 0.07725321888412018, 'fraction_numerical': 0.006531069229333831, 'mean_word_length': 3.4297520661157024, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3401897', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1444, 'n_words': 300}