Ignore:
Timestamp:
2009-09-03T18:51:04+02:00 (16 years ago)
Author:
Gubaer
Message:

improved upload dialog
new: tags for changesets
new: multiple uploads to the same changeset
fixed #3381: simple imput of a changeset source
fixed #2491: Allow arbitrary key-value pairs in changesets
fixed #2436: Allow multiple uploads to one changeset

Location:
trunk/src/org/openstreetmap/josm/io
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r2037 r2040  
    145145
    146146    /**
    147      * Returns true if the negotiated version supports changesets.
    148      * @return true if the negotiated version supports changesets.
    149      */
    150     public boolean hasChangesetSupport() {
     147     * Returns true if the negotiated version supports diff uploads.
     148     * @return true if the negotiated version supports diff uploads
     149     */
     150    public boolean hasSupportForDiffUploads() {
    151151        return ((version != null) && (version.compareTo("0.6")>=0));
    152152    }
     
    280280
    281281    /**
    282      * Creates a new changeset on the server to use for subsequent calls.
    283      * @param comment the "commit comment" for the new changeset
     282     * Creates the changeset to be used for subsequent uploads.
     283     *
     284     * If changesetProcessingType is {@see ChangesetProcessingType#USE_NEW} creates a new changeset based
     285     * on <code>changeset</code>. Otherwise uses the changeset given by {@see OsmApi#getCurrentChangeset()}.
     286     * If this changeset is null or has an id of value 0, a new changeset is created too.
     287     *
     288     * @param changeset the changeset to be used for uploading if <code>changesetProcessingType</code> is
     289     *   {@see ChangesetProcessingType#USE_NEW}
     290     * @param changesetProcessingType  how to handel changesets; set to {@see ChangesetProcessingType#USE_NEW} if null
     291     * @param progressMonitor the progress monitor
    284292     * @throws OsmTransferException signifying a non-200 return code, or connection errors
    285293     */
    286     public void createChangeset(String comment, ProgressMonitor progressMonitor) throws OsmTransferException {
    287         progressMonitor.beginTask((tr("Opening changeset...")));
     294    public void createChangeset(Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
     295        if (changesetProcessingType == null) {
     296            changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     297        }
    288298        try {
    289             changeset = new Changeset();
    290             Properties sysProp = System.getProperties();
    291             Object ua = sysProp.get("http.agent");
    292             changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
    293             changeset.put("comment", comment);
    294             createPrimitive(changeset, progressMonitor);
     299            progressMonitor.beginTask((tr("Creating changeset...")));
     300            if (changesetProcessingType.isUseNew()) {
     301                Properties sysProp = System.getProperties();
     302                Object ua = sysProp.get("http.agent");
     303                changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
     304                createPrimitive(changeset, progressMonitor);
     305                this.changeset = changeset;
     306                progressMonitor.setCustomText((tr("Successfully opened changeset {0}",changeset.getId())));
     307            } else {
     308                if (this.changeset == null || this.changeset.getId() == 0) {
     309                    progressMonitor.setCustomText((tr("No currently open changeset. Opening a new changeset...")));
     310                    System.out.println(tr("Warning: could not reuse an existing changeset as requested. Opening a new one."));
     311                    Properties sysProp = System.getProperties();
     312                    Object ua = sysProp.get("http.agent");
     313                    changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString());
     314                    createPrimitive(changeset, progressMonitor);
     315                    this.changeset = changeset;
     316                    progressMonitor.setCustomText((tr("Successfully opened changeset {0}",this.changeset.getId())));
     317                } else {
     318                    progressMonitor.setCustomText((tr("Reusing existing changeset {0}", this.changeset.getId())));
     319                }
     320            }
    295321        } finally {
    296322            progressMonitor.finishTask();
     
    301327     * Closes a changeset on the server.
    302328     *
     329     * @param changesetProcessingType how changesets are currently handled
     330     * @param progressMonitor the progress monitor
     331     *
    303332     * @throws OsmTransferException if something goes wrong.
    304333     */
    305     public void stopChangeset(ProgressMonitor progressMonitor) throws OsmTransferException {
    306         progressMonitor.beginTask(tr("Closing changeset {0}...", changeset.getId()));
     334    public void stopChangeset(ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
     335        if (changesetProcessingType == null) {
     336            changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     337        }
    307338        try {
     339            progressMonitor.beginTask(tr("Closing changeset..."));
    308340            initialize(progressMonitor);
    309             sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor);
    310             changeset = null;
     341            if (changesetProcessingType.isCloseAfterUpload()) {
     342                progressMonitor.setCustomText(tr("Closing changeset {0}...", changeset.getId()));
     343                if (this.changeset != null && this.changeset.getId() > 0) {
     344                    sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor);
     345                    changeset = null;
     346                }
     347            } else {
     348                progressMonitor.setCustomText(tr("Leaving changeset {0} open...", changeset.getId()));
     349            }
    311350        } finally {
    312351            progressMonitor.finishTask();
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r2037 r2040  
    1212import org.openstreetmap.josm.Main;
    1313import org.openstreetmap.josm.actions.UploadAction;
     14import org.openstreetmap.josm.data.osm.Changeset;
    1415import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    8182     *
    8283     * @param primitives the collection of primitives to upload
     84     * @param changeset the changeset to be used if <code>changesetProcessingType</code> indicates that
     85     *   a new changeset should be opened
     86     * @param changesetProcessingType how we handle changesets
    8387     * @param progressMonitor the progress monitor
    8488     * @throws OsmTransferException thrown if an exception occurs
    8589     */
    86     protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     90    protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
    8791        try {
    8892            progressMonitor.setTicksCount(primitives.size());
    89             api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false));
     93            api.createChangeset(changeset, changesetProcessingType,progressMonitor.createSubTaskMonitor(0, false));
    9094            uploadStartTime = System.currentTimeMillis();
    9195            for (OsmPrimitive osm : primitives) {
     
    121125
    122126                if (api.getCurrentChangeset() != null && api.getCurrentChangeset().getId() > 0) {
    123                     api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false));
     127                    api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false));
    124128                }
    125129            } catch(Exception e) {
     
    138142     * @throws OsmTransferException thrown if an exception occurs
    139143     */
    140     protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     144    protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
    141145        // upload everything in one changeset
    142146        //
    143147        try {
    144             api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false));
     148            api.createChangeset(changeset, changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false));
    145149            processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)));
    146150        } catch(OsmTransferException e) {
     
    150154        } finally {
    151155            try {
    152                 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false));
     156                api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false));
    153157            } catch (Exception ee) {
    154158                OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee);
     
    165169     * @param primitives list of objects to send
    166170     */
    167     public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     171    public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException {
    168172        processed = new LinkedList<OsmPrimitive>();
    169173
     
    171175
    172176        try {
    173             // check whether we can use changeset
     177            // check whether we can use diff upload
    174178            //
    175             boolean canUseChangeset = api.hasChangesetSupport();
    176             boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);
    177             if (useChangeset && ! canUseChangeset) {
    178                 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion));
    179                 useChangeset = false;
    180             }
    181 
    182             if (useChangeset) {
     179            boolean casUseDiffUploads = api.hasSupportForDiffUploads();
     180            boolean useDiffUpload = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);
     181            if (useDiffUpload && ! casUseDiffUploads) {
     182                System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use diff uploads, but API is not able to handle them. Ignoring diff upload.", "osm-server.atomic-upload", apiVersion));
     183                useDiffUpload = false;
     184            }
     185
     186            if (useDiffUpload) {
    183187                progressMonitor.beginTask(tr("Starting to upload in one request ..."));
    184                 uploadChangesAsDiffUpload(primitives, progressMonitor);
     188                uploadChangesAsDiffUpload(primitives,changeset, changesetProcessingType, progressMonitor);
    185189            } else {
    186190                progressMonitor.beginTask(tr("Starting to upload with one request per primitive ..."));
    187                 uploadChangesIndividually(primitives, progressMonitor);
     191                uploadChangesIndividually(primitives,changeset,changesetProcessingType, progressMonitor);
    188192            }
    189193        } finally {
Note: See TracChangeset for help on using the changeset viewer.