app/src/main/java/org/mcopenplatform/muoapi/ManagerClientUtils.java
c732d49e
 /*
  *
74ca6d11
  *   Copyright (C) 2020, University of the Basque Country (UPV/EHU)
c732d49e
  *
  *  Contact for licensing options: <licensing-mcpttclient(at)mcopenplatform(dot)com>
  *
  *  This file is part of MCOP MCPTT Client
  *
  *  This is free software: you can redistribute it and/or modify it under the terms of
  *  the GNU General Public License as published by the Free Software Foundation, either version 3
  *  of the License, or (at your option) any later version.
  *
  *  This is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *  See the GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License along
  *  with this program; if not, write to the Free Software Foundation, Inc.,
  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
 package org.mcopenplatform.muoapi;
 
175b478c
 import org.doubango.ngn.datatype.ms.gms.ns.common_policy.ExtensibleType;
 import org.doubango.ngn.datatype.ms.gms.ns.common_policy.OneType;
 import org.doubango.ngn.datatype.ms.gms.ns.common_policy.RuleType;
 import org.doubango.ngn.datatype.ms.gms.ns.list_service.ListServiceType;
 import org.doubango.ngn.datatype.ms.gms.ns.resource_lists.EntryType;
c732d49e
 
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
 class ManagerClientUtils {
 
 
175b478c
 
     protected enum TypeParticipant{
         URI,
         DISPLAY_NAME,
         TYPE
     }
 
     protected static List<String> getParticipantGroupsWithTypes(ListServiceType serviceType,TypeParticipant type){
         if(serviceType==null)return null;
         List<String> participants=new ArrayList<>();
         if(serviceType.getList()!=null && serviceType.getList().getEntry()!=null)
             for(EntryType entryType:serviceType.getList().getEntry()){
                 if(entryType.getUri()!=null && !entryType.getUri().isEmpty()){
                     String participant=new String();
                     switch (type){
                         case URI:
                             participant=entryType.getUri();
 
                             break;
                         case TYPE:
                             if(entryType.getParticipanttype()!=null && !entryType.getParticipanttype().trim().isEmpty()){
                                 participant=entryType.getParticipanttype();
                             }
                             break;
                         case DISPLAY_NAME:
                             if(entryType.getDisplayName()!=null && entryType.getDisplayName().getValue()!=null && !entryType.getDisplayName().getValue().trim().isEmpty())
                                 participant=entryType.getDisplayName().getValue();
                             break;
                     }
                     participants.add(participant);
                 }
             }
 
         return participants;
 
     }
 
c732d49e
     protected static List<String[]> getParticipantGroups(ListServiceType serviceType){
         if(serviceType==null)return null;
         List<String[]> participants=new ArrayList<>();
         if(serviceType.getList()!=null && serviceType.getList().getEntry()!=null)
             for(EntryType entryType:serviceType.getList().getEntry()){
                 if(entryType.getUri()!=null && !entryType.getUri().isEmpty()){
                     String[] participant=new String[3];
                     participant[0]=entryType.getUri();
                     if(entryType.getParticipanttype()!=null && !entryType.getParticipanttype().trim().isEmpty())
                         participant[1]=entryType.getParticipanttype();
                     if(entryType.getDisplayName()!=null && entryType.getDisplayName().getValue()!=null && !entryType.getDisplayName().getValue().trim().isEmpty())
                         participant[2]=entryType.getDisplayName().getValue();
                     participants.add(participant);
                 }
             }
 
         return participants;
 
     }
74ca6d11
     protected static Set<ConstantsMCOP.GroupInfoEventExtras.ActionRealTimeVideoType> getActionRealTimeVideoTypes(String userID, ListServiceType serviceType) {
         if (serviceType == null) return null;
         List<ConstantsMCOP.GroupInfoEventExtras.ActionRealTimeVideoType> actionRealTimeVideoTypes = new ArrayList<>();
 
         Boolean nonrealtimevideo=serviceType.getMcvideononrealtimevideomode();
         if(nonrealtimevideo!=null && nonrealtimevideo)actionRealTimeVideoTypes.add(ConstantsMCOP.GroupInfoEventExtras.ActionRealTimeVideoType.nonRealTime);
         Boolean nonurgentrealtime=serviceType.getMcvideononurgentrealtimevideomode();
         if(nonurgentrealtime!=null && nonurgentrealtime)actionRealTimeVideoTypes.add(ConstantsMCOP.GroupInfoEventExtras.ActionRealTimeVideoType.nonUrgentRealTime);
         Boolean urgentrealtimevide=serviceType.getMcvideourgentrealtimevideomode();
         if(urgentrealtimevide!=null && urgentrealtimevide)actionRealTimeVideoTypes.add(ConstantsMCOP.GroupInfoEventExtras.ActionRealTimeVideoType.urgentRealTime);
 
         //"LinkedHashSet" used to avoid the duplicate "allow"
         return new LinkedHashSet<>(actionRealTimeVideoTypes);
     }
c732d49e
 
     protected static Set<ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum> getAllowsGroups(String userID, ListServiceType serviceType){
         if(serviceType==null)return null;
         List<ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum> allowsType=new ArrayList<>();
         Boolean iniviteMember=serviceType.getInviteMembers();
175b478c
         if(iniviteMember!=null && iniviteMember){
74ca6d11
             allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.mcpttInviteMembersAllow);
175b478c
         }else{
             Boolean onnetworkIniviteMember=serviceType.getOnnetworkinvitemembers();
74ca6d11
             if(onnetworkIniviteMember!=null && onnetworkIniviteMember)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.mcpttInviteMembersAllow);
175b478c
         }
74ca6d11
 
c732d49e
         Boolean allowshortdataservice=serviceType.getMcdataallowshortdataservice();
74ca6d11
         if(allowshortdataservice!=null && allowshortdataservice)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.shortDataServiceAllow);
c732d49e
         Boolean allowfiledistribution=serviceType.getMcdataallowfiledistribution();
74ca6d11
         if(allowfiledistribution!=null && allowfiledistribution)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.fileDistributionAllow);
c732d49e
         Boolean allowconversationmanagement=serviceType.getMcdataallowconversationmanagement();
74ca6d11
         if(allowconversationmanagement!=null && allowconversationmanagement)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.conversationManagementAllow);
c732d49e
         Boolean allowtxcontrol=serviceType.getMcdataallowtxcontrol();
74ca6d11
         if(allowtxcontrol!=null && allowtxcontrol)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.txControlAllow);
c732d49e
         Boolean allowrxcontrol=serviceType.getMcdataallowrxcontrol();
74ca6d11
         if(allowrxcontrol!=null && allowrxcontrol)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.rxControlAllow);
c732d49e
         Boolean enhancedstatus=serviceType.getMcdataallowenhancedstatus();
74ca6d11
         if(enhancedstatus!=null && enhancedstatus)allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.enhancedStatusAllow);
c732d49e
         if(serviceType.getRuleset()!=null && serviceType.getRuleset().getRule()!=null && userID!=null)
             for(RuleType rule:serviceType.getRuleset().getRule())
                 if(rule.getActions()!=null &&
                         rule.getConditions()!=null
                         ){
175b478c
                     org.doubango.ngn.datatype.ms.gms.ns.common_policy.IdentityType identityType=null;
c732d49e
                     if(rule.getConditions().getIdentity()!=null &&
                             !rule.getConditions().getIdentity().isEmpty() &&
                             (identityType=rule.getConditions().getIdentity().get(0))!=null){
                         if(identityType.getOne()!=null)
                             for(OneType oneType:identityType.getOne())
                                 if(oneType.getId()!=null && !oneType.getId().trim().isEmpty() && oneType.getId().trim().compareTo(userID)==0){
                                     List<ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum> allowsType2=getAllowsGroups(rule.getActions());
                                     allowsType.addAll(allowsType2);
                                 }
 
                     }else if(rule.getConditions().getIslistmember()!=null){
                         List<ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum> allowsType2=getAllowsGroups(rule.getActions());
                         allowsType.addAll(allowsType2);
                     }
                 }
         //"LinkedHashSet" used to avoid the duplicate "allow"
         return new LinkedHashSet<>(allowsType);
     }
     private static List<ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum> getAllowsGroups(ExtensibleType extensibleType){
         List<ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum> allowsType=new ArrayList<>();
         if(extensibleType!=null){
             if(extensibleType.getAllowMCPTTemergencycall()!=null && extensibleType.getAllowMCPTTemergencycall())
74ca6d11
                 allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.mcpttEmergencyCallAllow);
c732d49e
             if(extensibleType.getAllowMCPTTemergencycall()!=null && extensibleType.getAllowMCPTTemergencyalert())
74ca6d11
                 allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.mcpttEmergencyAlertAllow);
c732d49e
             if(extensibleType.getAllowMCPTTemergencycall()!=null && extensibleType.getAllowimminentperilcall())
74ca6d11
                 allowsType.add(ConstantsMCOP.GroupInfoEventExtras.AllowTypeEnum.mcpttImminentPerilCallAllow);
c732d49e
         }
         return allowsType;
 
     }
 }