Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
*
* Copyright 2016,2017,2018 IBM - All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.hyperledger.fabric.sdk;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonValue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal;
import org.hyperledger.fabric.protos.common.MspPrincipal.MSPRole;
import org.hyperledger.fabric.protos.common.Policies;
import org.hyperledger.fabric.protos.common.Policies.SignaturePolicy;
import org.hyperledger.fabric.protos.peer.Collection;
import org.hyperledger.fabric.sdk.exception.ChaincodeCollectionConfigurationException;
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import static java.lang.String.format;
public class ChaincodeCollectionConfiguration {
private static final Log logger = LogFactory.getLog(ChaincodeCollectionConfiguration.class);
private static final Pattern noofPattern = Pattern.compile("^(\\d+)-of$");
Collection.CollectionConfigPackage getCollectionConfigPackage() {
return collectionConfigPackage;
}
private final Collection.CollectionConfigPackage collectionConfigPackage;
ChaincodeCollectionConfiguration(JsonArray jsonConfig) throws ChaincodeCollectionConfigurationException {
collectionConfigPackage = parse(jsonConfig);
if (collectionConfigPackage == null) {
throw new ChaincodeCollectionConfigurationException("Parsing collection configuration produce null configuration.");
}
}
ChaincodeCollectionConfiguration(Collection.CollectionConfigPackage collectionConfigPackage) {
this.collectionConfigPackage = collectionConfigPackage;
}
public byte[] getAsBytes() throws ChaincodeCollectionConfigurationException {
if (collectionConfigPackage == null) {
throw new ChaincodeCollectionConfigurationException("Collection configuration was null.");
}
return collectionConfigPackage.toByteArray();
}
/**
* Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in a YAML file.
*
* @param configFile The file containing the network configuration
* @return A new ChaincodeCollectionConfiguration instance
* @throws InvalidArgumentException
* @throws IOException
*/
public static ChaincodeCollectionConfiguration fromYamlFile(File configFile) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException {
return fromFile(configFile, false);
}
/**
* Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in a JSON file.
*
* @param configFile The file containing the network configuration
* @return A new ChaincodeCollectionConfiguration instance
* @throws InvalidArgumentException
* @throws IOException
*/
public static ChaincodeCollectionConfiguration fromJsonFile(File configFile) throws InvalidArgumentException, IOException, ChaincodeCollectionConfigurationException {
return fromFile(configFile, true);
}
/**
* Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in YAML format
*
* @param configStream A stream opened on a YAML document containing network configuration details
* @return A new ChaincodeCollectionConfiguration instance
* @throws InvalidArgumentException
*/
public static ChaincodeCollectionConfiguration fromYamlStream(InputStream configStream) throws InvalidArgumentException, ChaincodeCollectionConfigurationException {
logger.trace("ChaincodeCollectionConfiguration.fromYamlStream...");
// Sanity check
if (configStream == null) {
throw new InvalidArgumentException("ConfigStream must be specified");
}
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
List