Search in sources :

Example 1 with Space

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

the class TestOSIORestClient method testGetSpaceWorkItemsById.

@Test
public void testGetSpaceWorkItemsById() throws Exception {
    TestData testData = new TestData();
    TestUtils.initSpaces(requestProvider, testData);
    requestProvider.addGetRequest("/namedspaces/user", testData.spaces);
    OSIORestClient client = connector.getClient(repository, requestProvider);
    RepositoryLocation location = client.getClient().getLocation();
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_ID, "user");
    location.setProperty(IOSIORestConstants.REPOSITORY_AUTH_TOKEN, "xxxxxxTokenxxxxxx");
    OSIORestConfiguration configuration = connector.getRepositoryConfiguration(repository);
    configuration.getSpaces();
    Map<String, Space> externSpaces = configuration.getExternalSpaces();
    assertTrue(externSpaces != null);
    assertTrue(externSpaces.isEmpty());
    Space s1 = client.getSpaceById("SPACE-0001", repository);
    assertTrue(s1 != null);
    assertEquals(s1.getName(), "mywork");
    assertEquals(s1.getId(), "SPACE-0001");
    Space s2 = client.getSpaceById("SPACE-0003", repository);
    assertTrue(s2 != null);
    assertEquals(s2.getName(), "mywork");
    assertEquals(s2.getId(), "SPACE-0003");
    externSpaces = configuration.getExternalSpaces();
    assertTrue(externSpaces != null);
    assertEquals(externSpaces.get("SPACE-0003"), s2);
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) TestData(org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData) OSIORestClient(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient) OSIORestConfiguration(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration) RepositoryLocation(org.eclipse.mylyn.commons.repositories.core.RepositoryLocation) Test(org.junit.Test)

Example 2 with Space

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space 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 3 with Space

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space 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 4 with Space

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

the class OSIORestClient method getTaskData.

public void getTaskData(Set<String> taskIds, TaskRepository taskRepository, TaskDataCollector collector, IOperationMonitor monitor) throws OSIORestException {
    OSIORestConfiguration config;
    try {
        config = connector.getRepositoryConfiguration(taskRepository);
    } catch (CoreException e1) {
        throw new OSIORestException(e1);
    }
    for (String taskId : taskIds) {
        if (taskId.isEmpty()) {
            continue;
        }
        String user = userName;
        // $NON-NLS-1$
        String[] tokens = taskId.split("#");
        String spaceName = tokens[0];
        // check for workitem in space not owned by this user
        // in which case it is prefixed by username
        // $NON-NLS-1$
        String[] spaceTokens = spaceName.split("/");
        if (spaceTokens.length > 1) {
            spaceName = spaceTokens[1];
            user = spaceTokens[0];
        }
        String wiNumber = tokens[1];
        try {
            // We need to translate from the space's workitem number to the real id
            // The easiest way is to use a namedspaces request that we know will give
            // us a "ResourceMovedPermanently" error which will contain the URL of the
            // real location of the workitem which contains the workitem uuid.
            user = URLQueryEncoder.transform(user);
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String query = "/namedspaces/" + user + "/" + spaceName + "/workitems/" + wiNumber;
            // $NON-NLS-1$
            String wid = "";
            try {
                wid = restRequestProvider.getWID(monitor, client, query, taskRepository);
            } catch (OSIORestResourceMovedPermanentlyException e) {
                Header h = e.getHeader();
                HeaderElement[] elements = h.getElements();
                for (HeaderElement element : elements) {
                    if ("Location".equals(element.getName())) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        int index = element.getValue().indexOf("workitem/");
                        wid = element.getValue().substring(index + 9);
                    }
                }
            }
            // $NON-NLS-1$
            String workitemquery = "/workitems/" + wid;
            TaskData taskData = restRequestProvider.getSingleTaskData(monitor, client, connector, workitemquery, taskRepository);
            Space space = null;
            String spaceId = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey()).getValue();
            space = getSpaceById(spaceId, taskRepository);
            restRequestProvider.getTaskComments(monitor, client, space, taskData);
            restRequestProvider.getTaskCreator(monitor, client, taskData);
            restRequestProvider.getTaskLabels(monitor, client, space, taskData);
            restRequestProvider.getTaskLinks(monitor, client, this, space, taskData, config);
            setTaskAssignees(taskData);
            config.updateSpaceOptions(taskData);
            config.addValidOperations(taskData);
            collector.accept(taskData);
        } catch (RuntimeException | CoreException e) {
            // if the Throwable was wrapped in a RuntimeException in
            // OSIORestGetTaskData.JSonTaskDataDeserializer.deserialize()
            // we now remove the wrapper and throw an OSIORestException
            e.printStackTrace();
            Throwable cause = e.getCause();
            if (cause instanceof CoreException) {
                throw new OSIORestException(cause);
            }
        }
    }
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) HeaderElement(org.apache.http.HeaderElement) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData) CoreException(org.eclipse.core.runtime.CoreException) Header(org.apache.http.Header)

Example 5 with Space

use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space 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)

Aggregations

Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)12 CoreException (org.eclipse.core.runtime.CoreException)6 IStatus (org.eclipse.core.runtime.IStatus)5 WorkItemTypeData (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemTypeData)5 Status (org.eclipse.core.runtime.Status)4 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 WorkItemLinkTypeData (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.WorkItemLinkTypeData)4 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)3 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)3 Label (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Label)3 User (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.User)3 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)3 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)3 TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2