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.cms.search.solr.schema; 017 018import java.util.Arrays; 019import java.util.Map; 020 021import org.apache.solr.client.solrj.request.schema.SchemaRequest; 022 023/** 024 * Represents a copy field definition in a solr schema. 025 */ 026public class CopyFieldDefinition implements SchemaDefinition 027{ 028 029 /** The source field. */ 030 protected String _source; 031 032 /** The destination field. */ 033 protected String _destination; 034 035 /** 036 * Build a copy field definition. 037 * @param source The source field. 038 * @param destination The destination field. 039 */ 040 public CopyFieldDefinition(String source, String destination) 041 { 042 this._source = source; 043 this._destination = destination; 044 } 045 046 /** 047 * Build a copy field definition from a map of attributes. 048 * @param attributes the Map of attributes. 049 */ 050 public CopyFieldDefinition(Map<String, Object> attributes) 051 { 052 this._source = (String) attributes.get("source"); 053 this._destination = (String) attributes.get("dest"); 054 } 055 056 /** 057 * Get the source field. 058 * @return The source field. 059 */ 060 public String getSource() 061 { 062 return _source; 063 } 064 065 /** 066 * Set the source field. 067 * @param source the source field. 068 */ 069 public void setSource(String source) 070 { 071 this._source = source; 072 } 073 074 /** 075 * Get the destination field. 076 * @return The destination field. 077 */ 078 public String getDestination() 079 { 080 return _destination; 081 } 082 083 /** 084 * Set the destination field. 085 * @param destination the destination field. 086 */ 087 public void setDestination(String destination) 088 { 089 this._destination = destination; 090 } 091 092 public SchemaRequest.Update getSchemaUpdate() 093 { 094 return new SchemaRequest.AddCopyField(getSource(), Arrays.asList(getDestination())); 095 } 096 097 public boolean exists(SchemaFields schemaFields) 098 { 099 return schemaFields.hasCopyField(getSource(), getDestination()); 100 } 101}