import java.util.List;
import java.util.Map;

import models.User;

import com.avaje.ebean.Ebean;

import controllers.routes;
import play.Application;
import play.GlobalSettings;
import play.api.mvc.Handler;
import play.libs.Yaml;
import play.mvc.Http.RequestHeader;

public class Global extends GlobalSettings {
    public void onStart(Application app) {
    	insertDefaults();
    }

    private static void insertDefaults() {
        if (Ebean.find(User.class).findRowCount() == 0) {
            String initFileName = "initial-data.yml";

            @SuppressWarnings("unchecked")
            Map<String, List<Object>> all = (Map<String, List<Object>>) Yaml
                    .load(initFileName);

            String[] entityNames = {
                "users", "projects", "milestones",
                "issues", "issueComments",
                "postings", "postingComments",
                "roles", "projectUsers",
                "siteAdmins"
            };

            // Check whether every entities exist.
            for (String entityName : entityNames) {
                if (all.get(entityName) == null) {
                    throw new RuntimeException("Failed to find the '" + entityName
                            + "' entity in '" + initFileName + "'");
                }
            }

            for (String entityName : entityNames) {
                Ebean.save(all.get(entityName));
            }
        }
    }
    
    @Override
    public Handler onRouteRequest(RequestHeader request) {
        // Route here these webdav methods to be used for serving Subversion
        // repositories, because Play2 cannot route them.
        String[] webdavMethods = { "PROPFIND", "REPORT", "PROPPATCH", "COPY", "MOVE", "LOCK",
                "UNLOCK", "MKCOL", "VERSION-CONTROL", "MKWORKSPACE", "MKACTIVITY", "CHECKIN",
                "CHECKOUT", "MERGE", "TRACE" };
        for (String method : webdavMethods) {
            if (request.method().equalsIgnoreCase(method)) {
                return routes.ref.SvnApp.service().handler();
            }
        }
        return super.onRouteRequest(request);
    }

    public void onStop(Application app) {
    }
}

@@ -39,16 +39,83 @@
 l.Map;%0A%0A
+import models.Issue;%0Aimport models.Posting;%0Aimport models.Project;%0A
 import m
@@ -1473,32 +1473,708 @@
 ;%0A            %7D%0A
+%0A            // Do numbering for issues and postings.%0A            for (Project project : Project.find.findList()) %7B%0A                List%3CIssue%3E issues = Issue.finder.where()%0A                        .eq(%22project.id%22, project.id).orderBy(%22id desc%22)%0A                        .findList();%0A%0A                for (Issue issue: issues) %7B%0A                    issue.save();%0A                %7D%0A%0A                List%3CPosting%3E postings = Posting.finder.where()%0A                        .eq(%22project.id%22, project.id).orderBy(%22id desc%22)%0A                        .findList();%0A%0A                for (Posting posting: postings) %7B%0A                    posting.save();%0A                %7D%0A            %7D%0A%0A
         %7D%0A    %7D%0A

Fix constraint violation of number.