<commit_before>package io.github.data4all.network;

/**
 * the OsCUploadHelper handles the whole Uploading Process from 
 * requesting changeSet, parsing into Osc and uploading to the OSM API 
 * 
 */

import java.util.ArrayList;

import android.content.Context;
import android.preference.PreferenceManager;
import io.github.data4all.Constants;
import io.github.data4all.model.data.AbstractDataElement;
import io.github.data4all.task.RequestChangesetIDFromOpenStreetMapTask;
import io.github.data4all.task.UploadingOsmChangeFileToOpenStreetMapTask;
import io.github.data4all.util.OsmChangeParser;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;

/**
 * @author Richard
 *
 */
public class OscUploadHelper {

	private OAuthConsumer consumer;
	private Context context;
	private ArrayList<AbstractDataElement> elems;

	/**
	 * Constructor of the OscUploadHelper starts with the ChangeSetRequest
	 * 
	 * @param context
	 *            Context of the Application
	 * @param elems
	 *            List of Elements which should be uploaded
	 * @param comment
	 *            Comment of the Upload, should contain what was uploaded
	 */

	public OscUploadHelper(Context context,
			ArrayList<AbstractDataElement> elems, String comment) {
		consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY,
				Constants.CONSUMER_SECRET);
		this.context = context;
		this.elems = elems;
		consumer.setTokenWithSecret(
				PreferenceManager.getDefaultSharedPreferences(context)
						.getString("oauth_token", null),
				PreferenceManager.getDefaultSharedPreferences(context)
						.getString("oauth_token_secret", null));
		new RequestChangesetIDFromOpenStreetMapTask(context, consumer, comment,
				this).execute();
	}

	/**
	 * parseAndUpload is called in RequestChangesetIDFromOpenStreetMapTask with
	 * the requested changeSetID It parses the Osc file and starts the uploading
	 * task.
	 * 
	 * @param changeSetId
	 *            the changeSetId required for parsing and uploading
	 */

	public void parseAndUpload(Integer changeSetId) {
		OsmChangeParser.parseElements(context, elems, changeSetId);
		new UploadingOsmChangeFileToOpenStreetMapTask(context, consumer,
				changeSetId).execute();
	}
}<commit_msg>added license header, fixed sonarqube issues<commit_after>/*
 * Copyright (c) 2014, 2015 Data4All
 * 
 * <p>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
 * 
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 * 
 * <p>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 io.github.data4all.network;

/**
 * the OsCUploadHelper handles the whole Uploading Process from 
 * requesting changeSet, parsing into Osc and uploading to the OSM API 
 * 
 */

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.preference.PreferenceManager;
import io.github.data4all.Constants;
import io.github.data4all.model.data.AbstractDataElement;
import io.github.data4all.task.RequestChangesetIDFromOsmTask;
import io.github.data4all.task.UploadingOsmChangeFileToOpenStreetMapTask;
import io.github.data4all.util.OsmChangeParser;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;

/**
 * @author Richard
 *
 */
public class OscUploadHelper {

	private OAuthConsumer consumer;
	private Context context;
	private List<AbstractDataElement> elems;

	/**
	 * Constructor of the OscUploadHelper starts with the ChangeSetRequest.
	 * 
	 * @param context
	 *            Context of the Application
	 * @param elems
	 *            List of Elements which should be uploaded
	 * @param comment
	 *            Comment of the Upload, should contain what was uploaded
	 */

	public OscUploadHelper(Context context,
			List<AbstractDataElement> elems, String comment) {
		consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY,
				Constants.CONSUMER_SECRET);
		this.context = context;
		this.elems = elems;
		consumer.setTokenWithSecret(
				PreferenceManager.getDefaultSharedPreferences(context)
						.getString("oauth_token", null),
				PreferenceManager.getDefaultSharedPreferences(context)
						.getString("oauth_token_secret", null));
		new RequestChangesetIDFromOsmTask(context, consumer, comment,
				this).execute();
	}

	/**
	 * parseAndUpload is called in RequestChangesetIDFromOpenStreetMapTask with
	 * the requested changeSetID It parses the Osc file and starts the uploading
	 * task.
	 * 
	 * @param changeSetId
	 *            the changeSetId required for parsing and uploading
	 */

	public void parseAndUpload(Integer changeSetId) {
		OsmChangeParser.parseElements(context, elems, changeSetId);
		new UploadingOsmChangeFileToOpenStreetMapTask(context, consumer,
				changeSetId).execute();
	}
}
{'fraction_non_alphanumeric': 0.07806112517033288, 'fraction_numerical': 0.004866653688923496, 'mean_word_length': 4.465957446808511, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4891506', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1415, 'n_words': 401}