001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.core.right; 017 018import java.util.HashMap; 019import java.util.Map; 020 021/** 022 * This bean represents a profile 023 */ 024public class Profile 025{ 026 private String _id; 027 private String _label; 028 private String _context; 029 030 /** 031 * Constructor. 032 * @param id the unique id of this profile 033 * @param label the label of this profile 034 */ 035 public Profile(String id, String label) 036 { 037 this(id, label, null); 038 } 039 040 /** 041 * Constructor. 042 * @param id the unique id of this profile 043 * @param label the label of this profile 044 * @param context the context 045 */ 046 public Profile(String id, String label, String context) 047 { 048 _id = id; 049 _label = label; 050 _context = context; 051 } 052 053 /** 054 * Set the id of profile 055 * @param id The id to set 056 */ 057 public void setId (String id) 058 { 059 _id = id; 060 } 061 062 /** 063 * Returns the unique Id of this profile 064 * @return the unique Id of this profile 065 */ 066 public String getId() 067 { 068 return _id; 069 } 070 071 /** 072 * Returns the name of this profile 073 * @return the name of this profile 074 */ 075 public String getLabel() 076 { 077 return _label; 078 } 079 080 /** 081 * Set the label of profile 082 * @param label The label to set 083 */ 084 public void setLabel (String label) 085 { 086 _label = label; 087 } 088 089 /** 090 * Returns the context of this profile 091 * @return the context of this profile. Can be null. 092 */ 093 public String getContext() 094 { 095 return _context; 096 } 097 098 /** 099 * Set the context of profile 100 * @param context The context to set 101 */ 102 public void setContext (String context) 103 { 104 _context = context; 105 } 106 107 /** 108 * Get the JSON representation of this Profile 109 * @return The profile's properties 110 */ 111 public Map<String, Object> toJSON() 112 { 113 Map<String, Object> profile = new HashMap<>(); 114 115 profile.put("id", _id); 116 profile.put("label", _label); 117 profile.put("context", getContext()); 118 119 return profile; 120 } 121 122 123 @Override 124 public boolean equals(Object another) 125 { 126 if (another == null || !(another instanceof Profile)) 127 { 128 return false; 129 } 130 131 Profile otherProfile = (Profile) another; 132 133 return _id != null || _id.equals(otherProfile.getId()); 134 } 135 136 @Override 137 public int hashCode() 138 { 139 return _id.hashCode(); 140 } 141}