package net.coding.program.param;

import net.coding.program.MyApp;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by chenchao on 2017/4/17.
 * 携带了 project 的 创建者 和 项目名
 */
public class ProjectJumpParam implements Serializable {
    public String project = "";
    public String user = "";

    public ProjectJumpParam(String user, String project) {
        this.user = user;
        this.project = project;
    }

    public ProjectJumpParam(String path) {
        path = MyApp.transformEnterpriseUri(path);
        String[] regexs = new String[]{
                "^/u/(.*?)/p/(.*?)(?:/git)?$",
                "^/user/(.*)/project/(.*)$",
                "^/t/(.*?)/p/(.*?)(?:/git)?$",
                "^/team/(.*)/p/(.*)$",
                "^/team/(.*)/project/(.*)$"
        };
        for (String item : regexs) {
            if (isMatch(path, item)) {
                return;
            }
        }
    }

    private boolean isMatch(String path, String regex) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(path);
        if (matcher.find()) {
            this.user = matcher.group(1);
            this.project = matcher.group(2);
            return true;
        }

        return false;
    }

    public String toPath() {
        return String.format("/user/%s/project/%s", user, project);
    }
}

@@ -655,53 +655,8 @@
 $%22,%0A
-                %22%5E/user/(.*)/project/(.*)$%22,%0A
     
@@ -721,64 +721,42 @@
  %22%5E/
-team/(.*)/p/(.*)$%22,%0A                %22%5E/team/(.*)/
+(?:u%7Cuser%7Cteam)/(.*)/(?:
 project
+%7Cp)
 /(.*

修改 project path 正则表达式