1 /* 2 * The contents of this file are subject to the terms of the Common Development and 3 * Distribution License (the License). You may not use this file except in compliance with the 4 * License. 5 * 6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 7 * specific language governing permission and limitations under the License. 8 * 9 * When distributing Covered Software, include this CDDL Header Notice in each file and include 10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 11 * Header, with the fields enclosed by brackets [] replaced by your own identifying 12 * information: "Portions copyright [year] [name of copyright owner]". 13 * 14 * Copyright 2015-2016 ForgeRock AS. 15 */ 16 package org.forgerock.audit.handlers.jdbc; 17 18 import java.util.LinkedHashMap; 19 import java.util.Map; 20 21 import org.forgerock.json.JsonPointer; 22 23 /** 24 * Stores a pair of {@link TableMapping} and a map of parameters. 25 */ 26 class TableMappingParametersPair { 27 28 private TableMapping tableMapping; 29 private Map<String, Object> parameters; 30 31 /** 32 * Creates a TableMappingParametersPair given a {@link TableMapping}. A empty parameter map is created. 33 * @param tableMapping The {@link TableMapping} to create the pair with. 34 */ 35 public TableMappingParametersPair(final TableMapping tableMapping) { 36 this(tableMapping, new LinkedHashMap<String, Object>()); 37 } 38 39 /** 40 * Creates a TableMappingParametersPair given a {@link TableMapping} and parameter map. 41 * @param tableMapping A {@link TableMapping}. 42 * @param parameters A Map of replacement parameters. 43 */ 44 public TableMappingParametersPair(final TableMapping tableMapping, final Map<String, Object> parameters) { 45 this.tableMapping = tableMapping; 46 this.parameters = parameters; 47 } 48 49 /** 50 * Gets the {@link TableMapping} in the pair. 51 * @return A {@link TableMapping}. 52 */ 53 public TableMapping getTableMapping() { 54 return tableMapping; 55 } 56 57 /** 58 * Gets the replacement parameters in the pair. 59 * @return A map of replacement parameters. 60 */ 61 public Map<String, Object> getParameters() { 62 return parameters; 63 } 64 65 /** 66 * Utility method to get the column name out of a {@link TableMapping}. 67 * @param field The {@link JsonPointer} field to get the column of. 68 * @return The column name mapped to the given field. 69 */ 70 public String getColumnName(final JsonPointer field) { 71 final String fieldString = field.toString(); 72 if (tableMapping.getFieldToColumn().get(fieldString) != null) { 73 return tableMapping.getFieldToColumn().get(fieldString); 74 } else { 75 //remove forward slash and return the result 76 return tableMapping.getFieldToColumn().get(fieldString.substring(1)); 77 } 78 } 79 }