コード例 #1
0
Poco::JSON::Array::Ptr AuthorityRecordMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_AUTH_RECS);

	// Required parameters
	MQLONG options = 0;
	Poco::JSON::Array::Ptr optionsValue = _input->getArray("Options");
	if ( !optionsValue.isNull() )
	{
		for(Poco::JSON::Array::ValueVec::const_iterator it = optionsValue->begin(); it != optionsValue->end(); ++it)
		{
			std::string value = *it;
			if ( value.compare("Name All Matching") == 0 )
			{
				options |= MQAUTHOPT_NAME_ALL_MATCHING;
			}
			else if ( value.compare("Name Explicit") == 0 )
			{
				options |= MQAUTHOPT_NAME_EXPLICIT;
			}
			else if ( value.compare("Entity Explicit") == 0 )
			{
				options |= MQAUTHOPT_ENTITY_EXPLICIT;
			}
			else if ( value.compare("Entity Set") == 0 )
			{
				options |= MQAUTHOPT_ENTITY_SET;
			}
			else if ( value.compare("Name As Wildcard") == 0 )
			{
				options |= MQAUTHOPT_NAME_AS_WILDCARD;
			}
		}
		pcf()->addParameter(MQIACF_AUTH_OPTIONS, options);
	}
	// When no ProfileName is passed, set to empty string
	if ( !_input->has("ProfileName") ) _input->set("ProfileName", "");
	addParameter<std::string>(MQCACF_AUTH_PROFILE_NAME, "ProfileName");
	addParameterNumFromString(MQIACF_OBJECT_TYPE, "ObjectType");

	// Optional parameters
	addParameter<std::string>(MQCACF_ENTITY_NAME, "EntityName");
	addParameterNumFromString(MQIACF_ENTITY_TYPE, "EntityType");
	addAttributeList(MQIACF_AUTH_PROFILE_ATTRS, "ProfileAttrs");
	addParameter<std::string>(MQCACF_SERVICE_COMPONENT, "ServiceComponent");

	PCF::Vector commandResponse;
	execute(commandResponse);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();

	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
コード例 #2
0
void Controller::ingestRequest(const Poco::Dynamic::Var& request) {
    if (request.type() != typeid(Poco::JSON::Array::Ptr)) {
        throw RequestException("Invalid JSON format, root must be array.");
    }
    
    try {
        Poco::JSON::Array::Ptr jsonArray = request.extract<Poco::JSON::Array::Ptr>();
        
        for (Poco::JSON::Array::ConstIterator it = jsonArray->begin(); it != jsonArray->end(); it++) {
            Poco::JSON::Object::Ptr json = it->extract<Poco::JSON::Object::Ptr>();
            
            Record record;
            vector<uint8_t>* image_data = NULL;
            
            if (json->has("id")) {
                record.setId(json->getValue<string>("id"));
            }
            if (json->has("thumbnail")) {
                record.setThumbnail(json->getValue<string>("thumbnail"));
            }
            if (json->has("metadata")) {
                record.setMetadata(json->getValue<string>("metadata"));
            }
            if (json->has("blockHash")) {
                record.getHashes()[BlockHash] = str2bin(json->getValue<string>("blockHash"));
            }
            if (json->has("dHash")) {
                record.getHashes()[DHash] = str2bin(json->getValue<string>("dHash"));
            }
            if (json->has("gaussDHash")) {
                record.getHashes()[GaussDHash] = str2bin(json->getValue<string>("gaussDHash"));
            }
            if (json->has("gauss2DHash")) {
                record.getHashes()[Gauss2DHash] = str2bin(json->getValue<string>("gauss2DHash"));
            }
            if (json->has("gaussBlockHash")) {
                record.getHashes()[GaussBlockHash] = str2bin(json->getValue<string>("gaussBlockHash"));
            }
            if (json->has("image_base64")) {
                image_data = Image::fromBase64(json->getValue<string>("image_base64"));
            }
            if (!image_data && json->has("image_url")) {
                image_data = Image::fromUrl(json->getValue<string>("image_url"));
            }
            
            if (json->has("status")) {
                string status = json->getValue<string>("status");
                if (status == "deleted") {
                    deleteRequest(record);
                    continue;
                } else {
                    throw RequestException("Invalid status value.");
                }
            }

            if (image_data) {
                HashAlgorithmManager::getInstance().attachHashes(record, image_data);
                delete image_data;
            }
            putRequest(record);
        }
    } catch (Poco::JSON::JSONException& e) {
        throw RequestException("Invalid JSON format.");
    }
    appio::print_ok("Data was successfully changed.");
}