1 /* 2 * This file is part of *** M y C o R e *** 3 * See http://www.mycore.de/ for details. 4 * 5 * MyCoRe is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * MyCoRe is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 package org.mycore.orcid.works; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 24 import org.mycore.orcid.oauth.MCROAuthClient; 25 26 /** 27 * Represents the source application that generated the work entry in the ORCID profile. 28 * This may be another ORCID, another client application or THIS, our MyCoRe application. 29 * 30 * @author Frank L\u00FCtzenkirchen * 31 */ 32 public class MCRWorkSource { 33 34 private static Map<String, MCRWorkSource> sources = new HashMap<>(); 35 36 private String sourceID; 37 38 static MCRWorkSource getInstance(String sourceID) { 39 return sources.computeIfAbsent(sourceID, MCRWorkSource::new); 40 } 41 42 private MCRWorkSource(String sourceID) { 43 this.sourceID = sourceID; 44 } 45 46 public String getID() { 47 return sourceID; 48 } 49 50 /** 51 * Returns true, if this is our client application, that means 52 * the source's ID is our MCR.ORCID.OAuth.ClientID 53 */ 54 public boolean isThisApplication() { 55 return MCROAuthClient.instance().getClientID().equals(sourceID); 56 } 57 58 @Override 59 public boolean equals(Object obj) { 60 return (obj instanceof MCRWorkSource) && sourceID.equals(((MCRWorkSource) obj).sourceID); 61 } 62 63 @Override 64 public int hashCode() { 65 return sourceID.hashCode(); 66 } 67 }