Search in sources :

Example 1 with WorkItemTypeData

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData in project linuxtools by eclipse.

the class OSIORestClient method getConfiguration.

public OSIORestConfiguration getConfiguration(TaskRepository repository, IOperationMonitor monitor) {
    try {
        OSIORestConfiguration config = new OSIORestConfiguration(repository.getUrl(), userName);
        Map<String, Space> spaces = getSpaces(monitor);
        for (Space space : spaces.values()) {
            Map<String, WorkItemTypeData> workItemTypes = getSpaceWorkItemTypes(new NullOperationMonitor(), space);
            space.setWorkItemTypes(workItemTypes);
            Map<String, WorkItemLinkTypeData> workItemLinkTypes = getSpaceWorkItemLinkTypes(new NullOperationMonitor(), space);
            space.setWorkItemLinkTypes(workItemLinkTypes);
            Map<String, Area> areas = getSpaceAreas(new NullOperationMonitor(), space);
            space.setAreas(areas);
            Map<String, Iteration> iterations = getSpaceIterations(new NullOperationMonitor(), space);
            space.setIterations(iterations);
            Map<String, Label> labels = getSpaceLabels(new NullOperationMonitor(), space);
            space.setLabels(labels);
            Map<String, User> users = getUsers(new NullOperationMonitor(), space);
            space.setUsers(users);
        }
        config.setSpaces(spaces);
        return config;
    } catch (Exception e) {
        StatusHandler.log(// $NON-NLS-1$
        new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, "Could not get the Configuration", e));
        return null;
    }
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) User(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User) Label(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label) Iteration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration) WorkItemTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData) CoreException(org.eclipse.core.runtime.CoreException) Area(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area) WorkItemLinkTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeData)

Example 2 with WorkItemTypeData

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData in project linuxtools by eclipse.

the class OSIORestClient method getSpaceById.

@SuppressWarnings("deprecation")
public Space getSpaceById(String spaceId, TaskRepository taskRepository) throws CoreException {
    OSIORestConfiguration config = null;
    config = connector.getRepositoryConfiguration(taskRepository);
    Map<String, Space> spaces = config.getSpaces();
    Space space = null;
    for (Space s : spaces.values()) {
        if (s.getId().equals(spaceId)) {
            space = s;
            break;
        }
    }
    if (space == null) {
        Map<String, Space> externalSpaces = config.getExternalSpaces();
        space = externalSpaces.get(spaceId);
        if (space == null) {
            SpaceSingleResponse spaceResponse = null;
            try {
                spaceResponse = restRequestProvider.getSingleRequest(new NullOperationMonitor(), client, "/spaces/" + spaceId, new TypeToken<SpaceSingleResponse>() {
                });
                // spaceResponse = new OSIORestGetRequest<SpaceSingleResponse>(client, "/spaces/" + spaceId, new TypeToken<SpaceSingleResponse>() {}).run(new NullOperationMonitor());
                space = spaceResponse.getData();
                Map<String, WorkItemTypeData> workItemTypes = getSpaceWorkItemTypes(new NullOperationMonitor(), space);
                space.setWorkItemTypes(workItemTypes);
                Map<String, WorkItemLinkTypeData> workItemLinkTypes = getSpaceWorkItemLinkTypes(new NullOperationMonitor(), space);
                space.setWorkItemLinkTypes(workItemLinkTypes);
                Map<String, Area> areas = getSpaceAreas(new NullOperationMonitor(), space);
                space.setAreas(areas);
                Map<String, Iteration> iterations = getSpaceIterations(new NullOperationMonitor(), space);
                space.setIterations(iterations);
                Map<String, Label> labels = getSpaceLabels(new NullOperationMonitor(), space);
                space.setLabels(labels);
                Map<String, User> users = getUsers(new NullOperationMonitor(), space);
                space.setUsers(users);
            } catch (OSIORestException e) {
                com.google.common.base.Throwables.propagate(new CoreException(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$ //$NON-NLS-2$
                "Can not find Space (" + spaceId + ")")));
            }
            externalSpaces.put(space.getId(), space);
        }
    }
    return space;
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) User(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User) Label(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label) Iteration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration) WorkItemTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData) Area(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area) CoreException(org.eclipse.core.runtime.CoreException) TypeToken(com.google.gson.reflect.TypeToken) SpaceSingleResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceSingleResponse) WorkItemLinkTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeData)

Example 3 with WorkItemTypeData

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData in project linuxtools by eclipse.

the class OSIORestClient method formSearchUrl.

private String formSearchUrl(String url) throws OSIORestException {
    // $NON-NLS-1$
    String searchFilter = "";
    int index = url.indexOf("?");
    if (index < 0) {
        return searchFilter;
    }
    String query = url.substring(index + 1);
    // $NON-NLS-1$
    String[] settings = query.split("&");
    Map<String, Set<String>> fieldMap = new HashMap<>();
    for (String setting : settings) {
        // $NON-NLS-1$
        String[] tokens = setting.split("=");
        String name = tokens[0];
        String value = tokens[1];
        Set<String> field = fieldMap.get(name);
        if (field == null) {
            field = new TreeSet<>();
            fieldMap.put(name, field);
        }
        field.add(value);
    }
    if (!fieldMap.isEmpty()) {
        // $NON-NLS-1$
        searchFilter += "filter[expression]={\"$AND\":[";
        String lastKey = null;
        // $NON-NLS-1$
        String keySeparator = "";
        // $NON-NLS-1$
        String itemSeparator = "";
        Map<String, Space> spaces = getCachedSpaces(new NullOperationMonitor());
        Set<String> allSpaceNames = new TreeSet<>(spaces.keySet());
        Space firstSpace = spaces.values().iterator().next();
        Map<String, WorkItemTypeData> workitemTypes = firstSpace.getWorkItemTypes();
        for (String key : fieldMap.keySet()) {
            if (!key.equals(lastKey)) {
                // $NON-NLS-1$
                searchFilter += keySeparator + "{\"$OR\":[";
                // $NON-NLS-1$
                keySeparator = "]},";
                // $NON-NLS-1$
                itemSeparator = "";
            }
            if ("space".equals(key)) {
                // $NON-NLS-1$
                Set<String> spaceSet = fieldMap.get(key);
                for (String name : spaceSet) {
                    Space space = null;
                    if (spaces != null) {
                        space = spaces.get(name);
                    }
                    if (space != null) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        searchFilter += itemSeparator + "{\"space\":\"" + space.getId() + "\"}";
                        // $NON-NLS-1$
                        itemSeparator = ",";
                    }
                }
            } else if ("assignees".equals(key)) {
                // $NON-NLS-1$
                Set<String> userSet = fieldMap.get(key);
                Set<String> spaceNames = fieldMap.get("space") != null ? fieldMap.get("space") : allSpaceNames;
                for (String spaceName : spaceNames) {
                    // $NON-NLS-1$
                    Space space = cachedSpaces.get(spaceName);
                    if (space != null) {
                        Map<String, User> users = space.getUsers();
                        if (users != null) {
                            for (String name : userSet) {
                                User user = users.get(name);
                                if (user != null) {
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    searchFilter += itemSeparator + "{\"assignee\":\"" + user.getAttributes().getIdentityID() + "\"}";
                                    // $NON-NLS-1$
                                    itemSeparator = ",";
                                }
                            }
                        }
                    }
                }
            } else if ("baseType".equals(key)) {
                // $NON-NLS-1$
                Set<String> workitemSet = fieldMap.get(key);
                for (String name : workitemSet) {
                    WorkItemTypeData workitemType = null;
                    if (workitemTypes != null) {
                        workitemType = workitemTypes.get(name);
                    }
                    if (workitemType != null) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        searchFilter += itemSeparator + "{\"workitemtype\":\"" + workitemType.getId() + "\"}";
                        // $NON-NLS-1$
                        itemSeparator = ",";
                    }
                }
            } else if ("area".equals(key)) {
                // $NON-NLS-1$
                Set<String> areaSet = fieldMap.get(key);
                for (String spaceName : fieldMap.get("space")) {
                    // $NON-NLS-1$
                    Space space = cachedSpaces.get(spaceName);
                    if (space != null) {
                        Map<String, Area> areas = space.getAreas();
                        if (areas != null) {
                            for (String name : areaSet) {
                                Area area = areas.get(name);
                                if (area != null) {
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    searchFilter += itemSeparator + "{\"area\":\"" + area.getId() + "\"}";
                                    // $NON-NLS-1$
                                    itemSeparator = ",";
                                }
                            }
                        }
                    }
                }
            } else if ("iteration".equals(key)) {
                // $NON-NLS-1$
                Set<String> iterationSet = fieldMap.get(key);
                for (String spaceName : fieldMap.get("space")) {
                    // $NON-NLS-1$
                    Space space = cachedSpaces.get(spaceName);
                    if (space != null) {
                        Map<String, Iteration> iterations = space.getIterations();
                        if (iterations != null) {
                            for (String name : iterationSet) {
                                Iteration iteration = iterations.get(name);
                                if (iteration != null) {
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    searchFilter += itemSeparator + "{\"iteration\":\"" + iteration.getId() + "\"}";
                                    // $NON-NLS-1$
                                    itemSeparator = ",";
                                }
                            }
                        }
                    }
                }
            } else if ("system.state".equals(key)) {
                // $NON-NLS-1$
                Set<String> stateSet = fieldMap.get(key);
                for (String name : stateSet) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    searchFilter += itemSeparator + "{\"state\":\"" + name + "\"}";
                    // $NON-NLS-1$
                    itemSeparator = ",";
                }
            }
        }
        // $NON-NLS-1$
        searchFilter += "]}]}";
    }
    searchFilter = URLQueryEncoder.transform(searchFilter);
    return location.getUrl() + "/search?" + searchFilter;
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) Set(java.util.Set) TreeSet(java.util.TreeSet) User(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Iteration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration) WorkItemTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData) Area(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area) TreeSet(java.util.TreeSet) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 4 with WorkItemTypeData

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData in project linuxtools by eclipse.

the class TestUtils method initSpaces.

@SuppressWarnings("deprecation")
public static void initSpaces(OSIOTestRestRequestProvider requestProvider, TestData test) {
    GenericLinksForSpace myworkLinks = new GenericLinksForSpace("/api/spaces/SPACE-0001", "", "/api/spaces/SPACE-0001/workitemtypes", "/api/spaces/SPACE-0001/workitemlinktypes", "/api/spaces/SPACE-0001/collaborators", "", "", null);
    WorkItemTypeFieldType stateFieldType = new WorkItemTypeFieldType("enum", "string", "", new String[] { "new", "open", "in progress", "resolved", "closed" });
    WorkItemTypeField field1 = new WorkItemTypeField("System status", "Status", Boolean.TRUE, stateFieldType);
    Map<String, WorkItemTypeField> fieldMap = new HashMap<>();
    fieldMap.put("system.state", field1);
    WorkItemLinkTypeAttributes linkAttributes = new WorkItemLinkTypeAttributes("Bug Blocker", "a bug blocker", 1, "2017/01/01", "2017/01/01", "blocks", "is blocked by", null);
    WorkItemLinkTypeData linkType = new WorkItemLinkTypeData("LINKTYPE-0001", "workitemlinktypes", linkAttributes, null, null);
    test.defaultWorkItemLinkTypeResponse = (new WorkItemLinkTypeResponse(new WorkItemLinkTypeData[] { linkType }));
    WorkItemTypeAttributes bugTypeAttributes = new WorkItemTypeAttributes("bug", "A bug", 1, "bug", "2017/01/01", "2017/01/01", fieldMap);
    WorkItemTypeData bugData = new WorkItemTypeData("WORKITEMTYPE-0001", "workitemtypes", bugTypeAttributes, null);
    WorkItemTypeAttributes featureTypeAttributes = new WorkItemTypeAttributes("feature", "A feature", 1, "feature", "2017/01/01", "2017/01/01", fieldMap);
    WorkItemTypeData featureData = new WorkItemTypeData("WORKITEMTYPE-0002", "workitemtypes", featureTypeAttributes, null);
    WorkItemTypeData[] defaultWorkItemData = { bugData, featureData };
    test.defaultWorkItemTypeResponse = (new WorkItemTypeResponse(defaultWorkItemData));
    UserAttributes user1Attributes = new UserAttributes("user", "user", new Date(2017, 01, 01), new Date(2017, 01, 01), "User", "//imageurl", "user", Boolean.TRUE, "user@user.org", "userCo", "", "//users/user", "");
    User user1 = new User("USER-0001", "users", user1Attributes, null);
    UserAttributes user2Attributes = new UserAttributes("user2", "user2", new Date(2017, 01, 01), new Date(2017, 01, 01), "User2", "//imageurl", "user2", Boolean.TRUE, "user2@user.org", "userCo", "", "//users/user2", "");
    User user2 = new User("USER-0002", "users", user2Attributes, null);
    UsersResponse userResponse1 = new UsersResponse(new User[] { user1, user2 });
    AreaAttributes area1Attributes = new AreaAttributes("mywork", 1, "2017/01/01", "2017/01/01", "", "");
    Area area1 = new Area("AREA-0001", "areas", area1Attributes, null, null);
    AreaAttributes area2Attributes = new AreaAttributes("otherarea", 1, "2017/01/01", "2017/01/01", "", "");
    Area area2 = new Area("AREA-0002", "areas", area2Attributes, null, null);
    AreaListResponse areaResponse1 = new AreaListResponse(new Area[] { area1, area2 }, null, null);
    IterationAttributes iteration1Attributes = new IterationAttributes("mywork", "mywork iteration", "2017/01/01", "2017/01/01", "", "", "", true, true, "", "");
    Iteration iteration1 = new Iteration("ITERATION-0001", "iterations", iteration1Attributes, null, null);
    IterationListResponse iterationResponse1 = new IterationListResponse(new Iteration[] { iteration1 }, null, null);
    SpaceAttributes myworkAttributes = new SpaceAttributes("mywork", "My work space", 1, "", "");
    SpaceOwnedBy ownedBy = new SpaceOwnedBy(new IdentityRelationData("USER-0001", "users"), new GenericLinks("https://api.openshift.io/api/users/user", "https://api.openshift.io/api/users/user", null));
    SpaceRelationships relationships = new SpaceRelationships(ownedBy, null, null, null, null, null, null, null, null);
    Space mywork = new Space("SPACE-0001", "spaces", myworkAttributes, relationships, myworkLinks);
    SpaceSingleResponse myworkResponse = new SpaceSingleResponse(mywork);
    LabelAttributes label1Attributes = new LabelAttributes("label1", "2017/01/01", "2017/01/01", "1", "", "", "");
    Label label1 = new Label("labels", "LABEL-0001", label1Attributes, null, null);
    LabelAttributes label2Attributes = new LabelAttributes("label2", "2017/01/01", "2017/01/01", "1", "", "", "");
    Label label2 = new Label("labels", "LABEL-0002", label2Attributes, null, null);
    LabelListResponse labelResponse1 = new LabelListResponse(new Label[] { label1, label2 }, null, null);
    requestProvider.addGetRequest("/spaces/SPACE-0001/workitemlinktypes", test.defaultWorkItemLinkTypeResponse);
    requestProvider.addGetRequest("/spaces/SPACE-0001/workitemtypes", test.defaultWorkItemTypeResponse);
    requestProvider.addGetRequest("/spaces/SPACE-0001/collaborators", userResponse1);
    requestProvider.addGetRequest("/spaces/SPACE-0001", myworkResponse);
    requestProvider.addGetRequest("/namedspaces/user/mywork", mywork);
    requestProvider.addGetRequest("/spaces/SPACE-0001/areas", areaResponse1);
    requestProvider.addGetRequest("/spaces/SPACE-0001/iterations", iterationResponse1);
    requestProvider.addGetRequest("/spaces/SPACE-0001/labels", labelResponse1);
    requestProvider.addGetRequest("/users/user", new UserSingleResponse(user1));
    GenericLinksForSpace mywork2Links = new GenericLinksForSpace("/api/spaces/SPACE-0002", "", "/api/spaces/SPACE-0002/workitemtypes", "/api/spaces/SPACE-0002/workitemlinktypes", "/api/spaces/SPACE-0002/collaborators", "", "", null);
    UsersResponse userResponse2 = new UsersResponse(new User[] { user1 });
    AreaAttributes area3Attributes = new AreaAttributes("mywork2", 1, "2017/01/01", "2017/01/01", "", "");
    Area area3 = new Area("AREA-0003", "areas", area3Attributes, null, null);
    AreaListResponse areaResponse2 = new AreaListResponse(new Area[] { area3 }, null, null);
    IterationAttributes iteration2Attributes = new IterationAttributes("mywork2", "mywork2 iteration", "2017/01/01", "2017/01/01", "", "", "", true, true, "", "");
    Iteration iteration2 = new Iteration("ITERATION-0002", "iterations", iteration2Attributes, null, null);
    IterationAttributes iteration3Attributes = new IterationAttributes("otheriteration", "mywork2 other iteration", "2017/01/01", "2017/01/01", "", "", "", true, true, "", "");
    Iteration iteration3 = new Iteration("ITERATION-0003", "iterations", iteration3Attributes, null, null);
    IterationListResponse iterationResponse2 = new IterationListResponse(new Iteration[] { iteration2, iteration3 }, null, null);
    SpaceAttributes mywork2Attributes = new SpaceAttributes("mywork2", "My work space2", 1, "", "");
    SpaceRelationships relationships2 = new SpaceRelationships(ownedBy, null, null, null, null, null, null, null, null);
    Space mywork2 = new Space("SPACE-0002", "spaces", mywork2Attributes, relationships2, mywork2Links);
    SpaceSingleResponse mywork2Response = new SpaceSingleResponse(mywork2);
    LabelAttributes label3Attributes = new LabelAttributes("label3", "2017/01/01", "2017/01/01", "1", "", "", "");
    Label label3 = new Label("labels", "LABEL-0003", label3Attributes, null, null);
    LabelAttributes label4Attributes = new LabelAttributes("label4", "2017/01/01", "2017/01/01", "1", "", "", "");
    Label label4 = new Label("labels", "LABEL-0004", label4Attributes, null, null);
    LabelListResponse labelResponse2 = new LabelListResponse(new Label[] { label3, label4 }, null, null);
    requestProvider.addGetRequest("/spaces/SPACE-0002/workitemlinktypes", test.defaultWorkItemLinkTypeResponse);
    requestProvider.addGetRequest("/spaces/SPACE-0002/workitemtypes", test.defaultWorkItemTypeResponse);
    requestProvider.addGetRequest("/spaces/SPACE-0002/collaborators", userResponse2);
    requestProvider.addGetRequest("/spaces/SPACE-0002", mywork2Response);
    requestProvider.addGetRequest("/namedspaces/user/mywork2", mywork2);
    requestProvider.addGetRequest("/spaces/SPACE-0002/areas", areaResponse2);
    requestProvider.addGetRequest("/spaces/SPACE-0002/iterations", iterationResponse2);
    requestProvider.addGetRequest("/spaces/SPACE-0002/labels", labelResponse2);
    requestProvider.addGetRequest("/users/user2", new UserSingleResponse(user2));
    GenericLinksForSpace mywork3Links = new GenericLinksForSpace("/api/spaces/SPACE-0003", "", "/api/spaces/SPACE-0003/workitemtypes", "/api/spaces/SPACE-0003/workitemlinktypes", "/api/spaces/SPACE-0003/collaborators", "", "", null);
    UsersResponse userResponse3 = new UsersResponse(new User[] { user2 });
    AreaAttributes area4Attributes = new AreaAttributes("mywork", 1, "2017/01/01", "2017/01/01", "", "");
    Area area4 = new Area("AREA-0004", "areas", area4Attributes, null, null);
    AreaListResponse areaResponse3 = new AreaListResponse(new Area[] { area4 }, null, null);
    IterationAttributes iteration4Attributes = new IterationAttributes("mywork", "mywork b iteration", "2017/01/01", "2017/01/01", "", "", "", true, true, "", "");
    Iteration iteration4 = new Iteration("ITERATION-0004", "iterations", iteration4Attributes, null, null);
    IterationListResponse iterationResponse3 = new IterationListResponse(new Iteration[] { iteration4 }, null, null);
    SpaceAttributes mywork3Attributes = new SpaceAttributes("mywork", "My work space3", 1, "", "");
    SpaceOwnedBy ownedBy3 = new SpaceOwnedBy(new IdentityRelationData("USER-0002", "users"), new GenericLinks("https://api.openshift.io/api/users/user2", "https://api.openshift.io/api/users/user2", null));
    SpaceRelationships relationships3 = new SpaceRelationships(ownedBy3, null, null, null, null, null, null, null, null);
    Space mywork3 = new Space("SPACE-0003", "spaces", mywork3Attributes, relationships3, mywork3Links);
    SpaceSingleResponse mywork3Response = new SpaceSingleResponse(mywork3);
    LabelAttributes label5Attributes = new LabelAttributes("label5", "2017/01/01", "2017/01/01", "1", "", "", "");
    Label label5 = new Label("labels", "LABEL-0005", label5Attributes, null, null);
    LabelListResponse labelResponse3 = new LabelListResponse(new Label[] { label5 }, null, null);
    requestProvider.addGetRequest("/spaces/SPACE-0003/workitemlinktypes", test.defaultWorkItemLinkTypeResponse);
    requestProvider.addGetRequest("/spaces/SPACE-0003/workitemtypes", test.defaultWorkItemTypeResponse);
    requestProvider.addGetRequest("/spaces/SPACE-0003/collaborators", userResponse3);
    requestProvider.addGetRequest("/spaces/SPACE-0003", mywork3Response);
    requestProvider.addGetRequest("/namedspaces/user2/mywork", mywork3);
    requestProvider.addGetRequest("/spaces/SPACE-0003/areas", areaResponse3);
    requestProvider.addGetRequest("/spaces/SPACE-0003/iterations", iterationResponse3);
    requestProvider.addGetRequest("/spaces/SPACE-0003/labels", labelResponse3);
    Map<String, Space> spaceMap = new TreeMap<>();
    spaceMap.put("mywork", mywork);
    spaceMap.put("mywork2", mywork2);
    test.spaceMap = spaceMap;
    SpaceResponse spaces = new SpaceResponse(new Space[] { mywork, mywork2 }, null, new SpaceListMeta(2));
    test.spaces = spaces;
    SpaceResponse externalspaces = new SpaceResponse(new Space[] { mywork3 }, null, new SpaceListMeta(1));
    test.externalspaces = externalspaces;
    requestProvider.addGetRequest("/namedspaces/user", spaces);
}
Also used : AreaAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.AreaAttributes) User(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User) SpaceListMeta(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceListMeta) HashMap(java.util.HashMap) UsersResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.UsersResponse) Label(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label) WorkItemLinkTypeResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeResponse) Iteration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration) WorkItemTypeAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeAttributes) AreaListResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.AreaListResponse) UserAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.UserAttributes) GenericLinks(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.GenericLinks) SpaceResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceResponse) WorkItemTypeFieldType(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeFieldType) IdentityRelationData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IdentityRelationData) WorkItemLinkTypeAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeAttributes) SpaceSingleResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceSingleResponse) Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) GenericLinksForSpace(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.GenericLinksForSpace) IterationAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IterationAttributes) WorkItemTypeField(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeField) SpaceAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceAttributes) WorkItemTypeResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeResponse) LabelListResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.LabelListResponse) GenericLinksForSpace(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.GenericLinksForSpace) TreeMap(java.util.TreeMap) LabelAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.LabelAttributes) WorkItemTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData) Date(java.sql.Date) Area(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area) SpaceRelationships(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceRelationships) SpaceOwnedBy(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceOwnedBy) IterationListResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.IterationListResponse) UserSingleResponse(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.UserSingleResponse) WorkItemLinkTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeData)

Example 5 with WorkItemTypeData

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData in project linuxtools by eclipse.

the class OSIORestConfiguration method updateSpaceOptions.

public boolean updateSpaceOptions(@NonNull TaskData taskData) {
    if (taskData == null) {
        return false;
    }
    TaskAttribute attributeSpaceId = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE_ID.getKey());
    TaskAttribute attributeSpace = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE.getKey());
    if (attributeSpaceId != null && !attributeSpaceId.getValue().isEmpty()) {
        Space actualSpace = getSpaceById(attributeSpaceId.getValue());
        if (actualSpace == null) {
            return false;
        }
        TaskAttribute attributeWorkItemType = taskData.getRoot().getMappedAttribute(SCHEMA.WORKITEM_TYPE.getKey());
        if (attributeWorkItemType != null) {
            setAttributeOptionsForSpace(attributeWorkItemType, actualSpace);
        }
        TaskAttribute attributeArea = taskData.getRoot().getMappedAttribute(SCHEMA.AREA.getKey());
        if (attributeArea != null) {
            setAttributeOptionsForSpace(attributeArea, actualSpace);
        }
        TaskAttribute attributeIteration = taskData.getRoot().getMappedAttribute(SCHEMA.ITERATION.getKey());
        if (attributeIteration != null) {
            setAttributeOptionsForSpace(attributeIteration, actualSpace);
        }
        TaskAttribute attributeAddAssignee = taskData.getRoot().getMappedAttribute(SCHEMA.ADD_ASSIGNEE.getKey());
        if (attributeAddAssignee != null) {
            setAttributeOptionsForSpace(attributeAddAssignee, actualSpace);
        }
        TaskAttribute attributeAddLabel = taskData.getRoot().getMappedAttribute(SCHEMA.ADD_LABEL.getKey());
        if (attributeAddLabel != null) {
            setAttributeOptionsForSpace(attributeAddLabel, actualSpace);
        }
        TaskAttribute attributeState = taskData.getRoot().getMappedAttribute(SCHEMA.STATUS.getKey());
        if (attributeState != null) {
            setAttributeOptionsForSpace(attributeState, actualSpace);
        }
    } else {
        SortedSet<String> workItemTypes = new TreeSet<>();
        SortedSet<String> areas = new TreeSet<>();
        SortedSet<String> iterations = new TreeSet<>();
        SortedSet<String> users = new TreeSet<>();
        Set<String> states = new LinkedHashSet<>();
        for (Space space : getSpaces().values()) {
            if (attributeSpace != null) {
                attributeSpace.putOption(space.getName(), space.getName());
            }
            if (space.getWorkItemTypes() != null) {
                // assume first workItemType is representative of all with regards to states
                if (!space.getWorkItemTypes().isEmpty()) {
                    WorkItemTypeData data = space.getWorkItemTypes().values().iterator().next();
                    WorkItemTypeAttributes attributes = data.getWorkItemTypeAttributes();
                    Map<String, WorkItemTypeField> fields = attributes.getFields();
                    // $NON-NLS-1$
                    WorkItemTypeField state = fields.get("system.state");
                    WorkItemTypeFieldType stateType = state.getType();
                    String[] values = stateType.getValues();
                    if (values != null) {
                        for (String value : values) {
                            states.add(value);
                        }
                    }
                }
                for (Entry<String, WorkItemTypeData> entry : space.getWorkItemTypes().entrySet()) {
                    workItemTypes.add(entry.getKey());
                }
            }
            if (space.getAreas() != null) {
                for (String entry : space.getAreas().keySet()) {
                    areas.add(entry);
                }
            }
            if (space.getIterations() != null) {
                for (String entry : space.getIterations().keySet()) {
                    iterations.add(entry);
                }
            }
            if (space.getUsers() != null) {
                for (String entry : space.getUsers().keySet()) {
                    users.add(entry);
                }
            }
        }
        TaskAttribute attributeWorkItemType = taskData.getRoot().getMappedAttribute(SCHEMA.WORKITEM_TYPE.getKey());
        if (attributeWorkItemType != null) {
            setAllAttributeOptions(attributeWorkItemType, workItemTypes);
        }
        TaskAttribute attributeState = taskData.getRoot().getMappedAttribute(SCHEMA.STATUS.getKey());
        if (attributeState != null) {
            setAllAttributeOptions(attributeState, states);
        }
        TaskAttribute attributeAssignees = taskData.getRoot().getMappedAttribute(SCHEMA.ASSIGNEES.getKey());
        if (attributeAssignees != null && attributeAssignees.getOptions().size() == 0) {
            attributeAssignees.putOption(userName, userName);
        }
    }
    return true;
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) LinkedHashSet(java.util.LinkedHashSet) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) WorkItemTypeField(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeField) WorkItemTypeAttributes(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeAttributes) WorkItemTypeData(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData) TreeSet(java.util.TreeSet) WorkItemTypeFieldType(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeFieldType)

Aggregations

Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)5 WorkItemTypeData (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData)5 Area (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Area)4 Iteration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Iteration)4 User (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User)4 Label (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label)3 WorkItemLinkTypeData (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeData)3 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 SpaceSingleResponse (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.SpaceSingleResponse)2 WorkItemTypeAttributes (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeAttributes)2 WorkItemTypeField (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeField)2 WorkItemTypeFieldType (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeFieldType)2 TypeToken (com.google.gson.reflect.TypeToken)1 Date (java.sql.Date)1 LinkedHashMap (java.util.LinkedHashMap)1