<commit_before>/*
 *
 *  Copyright 2012-2014 Eurocommercial Properties NV
 *
 *
 *  Licensed under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.incode.module.communications.dom.mixins;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;

import com.google.common.collect.Lists;

import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.ActionLayout;
import org.apache.isis.applib.annotation.Contributed;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.Mixin;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.SemanticsOf;

import org.incode.module.communications.dom.impl.comms.Communication;
import org.incode.module.communications.dom.impl.covernotes.Document_coverNoteFor;
import org.incode.module.document.dom.DocumentModule;
import org.incode.module.document.dom.impl.docs.Document;
import org.incode.module.document.dom.impl.paperclips.PaperclipRepository;
import org.incode.module.document.dom.spi.SupportingDocumentsEvaluator;

@Mixin
public class Document_communications {

    private final Document document;

    public Document_communications(final Document document) {
        this.document = document;
    }

    public static class ActionDomainEvent extends DocumentModule.ActionDomainEvent<Document_communications> { }

    @Action(
            semantics = SemanticsOf.SAFE,
            domainEvent = ActionDomainEvent.class
    )
    @ActionLayout(
            contributed = Contributed.AS_ASSOCIATION
    )
    public List<Communication> $$() {
        final List<Communication> communications = Lists.newArrayList(
                paperclipRepository.findByDocument(document).stream()
                                    .map(paperclip -> paperclip.getAttachedTo())
                                    .filter(attachedTo -> attachedTo instanceof Communication)
                                    .map(Communication.class::cast)
                                    .collect(Collectors.toList()));
        Collections.reverse(communications);
        return communications;
    }

    public boolean hide$$() {
        // hide for supporting documents
        for (SupportingDocumentsEvaluator supportingDocumentsEvaluator : supportingDocumentsEvaluators) {
            final SupportingDocumentsEvaluator.Evaluation evaluation =
                    supportingDocumentsEvaluator.evaluate(document);
            if(evaluation == SupportingDocumentsEvaluator.Evaluation.SUPPORTING) {
                return true;
            }
        }


        return false;
    }

    @DomainService(
            nature = NatureOfService.DOMAIN,
            menuOrder = "110"
    )
    public static class SupportingDocumentsEvaluatorForCoverNotes implements SupportingDocumentsEvaluator {

        @Override
        public Document supportedBy(final Document candidateSupportingDocument) {
            return null;
        }

        @Override
        public Evaluation evaluate(final Document candidateSupportingDocument) {
            final Communication communication = coverNoteEvaluator.coverNoteFor(candidateSupportingDocument);
            return communication != null ? Evaluation.SUPPORTING : Evaluation.UNKNOWN;

        }<commit_msg>updates for change in document SPI, that SupportingDocumentsEvaluator<commit_after>/*
 *
 *  Copyright 2012-2014 Eurocommercial Properties NV
 *
 *
 *  Licensed under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.incode.module.communications.dom.mixins;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;

import com.google.common.collect.Lists;

import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.ActionLayout;
import org.apache.isis.applib.annotation.Contributed;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.Mixin;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.SemanticsOf;

import org.incode.module.communications.dom.impl.comms.Communication;
import org.incode.module.communications.dom.impl.covernotes.Document_coverNoteFor;
import org.incode.module.document.dom.DocumentModule;
import org.incode.module.document.dom.impl.docs.Document;
import org.incode.module.document.dom.impl.paperclips.PaperclipRepository;
import org.incode.module.document.dom.spi.SupportingDocumentsEvaluator;

@Mixin
public class Document_communications {

    private final Document document;

    public Document_communications(final Document document) {
        this.document = document;
    }

    public static class ActionDomainEvent extends DocumentModule.ActionDomainEvent<Document_communications> { }

    @Action(
            semantics = SemanticsOf.SAFE,
            domainEvent = ActionDomainEvent.class
    )
    @ActionLayout(
            contributed = Contributed.AS_ASSOCIATION
    )
    public List<Communication> $$() {
        final List<Communication> communications = Lists.newArrayList(
                paperclipRepository.findByDocument(document).stream()
                                    .map(paperclip -> paperclip.getAttachedTo())
                                    .filter(attachedTo -> attachedTo instanceof Communication)
                                    .map(Communication.class::cast)
                                    .collect(Collectors.toList()));
        Collections.reverse(communications);
        return communications;
    }

    public boolean hide$$() {
        // hide for supporting documents
        for (SupportingDocumentsEvaluator supportingDocumentsEvaluator : supportingDocumentsEvaluators) {
            final SupportingDocumentsEvaluator.Evaluation evaluation =
                    supportingDocumentsEvaluator.evaluate(document);
            if(evaluation == SupportingDocumentsEvaluator.Evaluation.SUPPORTING) {
                return true;
            }
        }


        return false;
    }

    @DomainService(
            nature = NatureOfService.DOMAIN,
            menuOrder = "110"
    )
    public static class SupportingDocumentsEvaluatorForCoverNotes implements SupportingDocumentsEvaluator {

        @Override
        public List<Document> supportedBy(final Document candidateSupportingDocument) {
            return null;
        }

        @Override
        public Evaluation evaluate(final Document candidateSupportingDocument) {
            final Communication communication = coverNoteEvaluator.coverNoteFor(candidateSupportingDocument);
            return communication != null ? Evaluation.SUPPORTING : Evaluation.UNKNOWN;
        }
{'fraction_non_alphanumeric': 0.077297782335598, 'fraction_numerical': 0.0038456608127163186, 'mean_word_length': 3.0237235688499227, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5633296', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1911, 'n_words': 453}