001// Generated by delombok at Mon Oct 12 23:00:28 BST 2020
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.isis.extensions.secman.api.permission;
021
022import java.util.Optional;
023import org.apache.isis.applib.annotation.Programmatic;
024import org.apache.isis.core.metamodel.services.appfeat.ApplicationFeatureId;
025import org.apache.isis.core.metamodel.services.appfeat.ApplicationFeatureType;
026import org.apache.isis.extensions.secman.api.IsisModuleExtSecmanApi;
027import org.apache.isis.extensions.secman.api.role.ApplicationRole;
028
029public interface ApplicationPermission {
030    // -- DOMAIN EVENTS
031    abstract class PropertyDomainEvent<T> extends IsisModuleExtSecmanApi.PropertyDomainEvent<ApplicationPermission, T> {
032    }
033
034
035    abstract class CollectionDomainEvent<T> extends IsisModuleExtSecmanApi.CollectionDomainEvent<ApplicationPermission, T> {
036    }
037
038
039    abstract class ActionDomainEvent extends IsisModuleExtSecmanApi.ActionDomainEvent<ApplicationPermission> {
040    }
041
042
043    class AllowDomainEvent extends ActionDomainEvent {
044    }
045
046
047    class UpdateRoleDomainEvent extends ActionDomainEvent {
048    }
049
050
051    class VetoDomainEvent extends ActionDomainEvent {
052    }
053
054
055    class DeleteDomainEvent extends ActionDomainEvent {
056    }
057
058
059    class ChangingDomainEvent extends ActionDomainEvent {
060    }
061
062
063    class ViewingDomainEvent extends ActionDomainEvent {
064    }
065
066    // -- MODEL
067    /**
068     * having a title() method (rather than using @Title annotation) is necessary as a workaround to be able to use
069
070     * wrapperFactory#unwrap(...) method, which is otherwise broken in Isis 1.6.0
071     */
072    default String title() {
073        final java.lang.StringBuilder buf = new StringBuilder();
074        // admin:
075        // Allow|Veto
076        // Viewing|Changing
077        buf.append(getRole().getName()).append(":").append(" ").append(getRule().toString()).append(" ").append(getMode().toString()).append(" of ");
078        createFeatureId().ifPresent(featureId -> {
079            switch (featureId.getType()) {
080            case PACKAGE: 
081                buf.append(getFeatureFqn()); // com.mycompany
082                break;
083            case CLASS: 
084                // abbreviate if required because otherwise title overflows on action prompt.
085                if (getFeatureFqn().length() < 30) {
086                    buf.append(getFeatureFqn()); // com.mycompany.Bar
087                } else {
088                    buf.append(featureId.getClassName()); // Bar
089                }
090                break;
091            case MEMBER: 
092                buf.append(featureId.getClassName()).append("#").append(featureId.getMemberName()); // com.mycompany.Bar#foo
093                break;
094            }
095        });
096        return buf.toString();
097    }
098
099    ApplicationFeatureType getFeatureType();
100
101    String getFeatureFqn();
102
103    ApplicationPermissionRule getRule();
104
105    void setRule(ApplicationPermissionRule rule);
106
107    ApplicationPermissionMode getMode();
108
109    void setMode(ApplicationPermissionMode changing);
110
111    ApplicationRole getRole();
112
113    void setRole(ApplicationRole applicationRole);
114
115    // -- HELPER
116    @Programmatic
117    default Optional<ApplicationFeatureId> createFeatureId() {
118        return Optional.of(getFeatureType()).map(featureType -> ApplicationFeatureId.newFeature(featureType, getFeatureFqn()));
119    }
120}