org.geogit.osm.base.AddOSMLogEntry.java Source code

Java tutorial

Introduction

Here is the source code for org.geogit.osm.base.AddOSMLogEntry.java

Source

/* Copyright (c) 2013 OpenPlans. All rights reserved.
 * This code is licensed under the BSD New License, available at the root
 * application directory.
 */
package org.geogit.osm.base;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.geogit.api.AbstractGeoGitOp;

import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.io.Files;
import com.google.inject.Inject;

/**
 * Adds an entry to the OSM log. The osm is used to keep track of trees created after importing from
 * OSM data, o they can be used as starting points for updating. The log is basically a list of
 * those trees that represent a dataset that correspond to given OSM snapshot and can, therefore, be
 * used to synchronize
 */
public class AddOSMLogEntry extends AbstractGeoGitOp<Void> {

    private OSMLogEntry entry;

    @Inject
    public AddOSMLogEntry() {

    }

    public AddOSMLogEntry setEntry(OSMLogEntry entry) {
        this.entry = entry;
        return this;
    }

    @Override
    public Void call() {
        URL file = command(ResolveOSMLogfile.class).call();
        try {
            Files.append(entry.toString() + "\n", new File(file.getFile()), Charsets.UTF_8);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        return null;
    }

}