use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space 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;
}
use of org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space in project linuxtools by eclipse.
the class OSIORestTaskAttributeMapper method getOptions.
@Override
public Map<String, String> getOptions(@NonNull TaskAttribute attribute) {
OSIORestTaskSchema taskSchema = OSIORestTaskSchema.getDefault();
if (attribute.getId().equals(taskSchema.WORKITEM_TYPE.getKey()) || attribute.getId().equals(taskSchema.AREA.getKey()) || attribute.getId().equals(taskSchema.ASSIGNEES.getKey()) || attribute.getId().equals(taskSchema.STATUS.getKey()) || attribute.getId().equals(taskSchema.ITERATION.getKey())) {
TaskAttribute spaceIdAttribute = attribute.getParentAttribute().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey());
TaskAttribute spaceAttribute = attribute.getParentAttribute().getAttribute(OSIORestCreateTaskSchema.getDefault().SPACE.getKey());
OSIORestConfiguration repositoryConfiguration;
try {
repositoryConfiguration = connector.getRepositoryConfiguration(this.getTaskRepository());
// TODO: change this when we have offline cache for the repository configuration so we build the options in an temp var
if (repositoryConfiguration != null) {
if (spaceIdAttribute != null && !spaceIdAttribute.getValue().equals("")) {
// $NON-NLS-1$
attribute.clearOptions();
for (String spaceId : spaceIdAttribute.getValues()) {
Space actualSpace = connector.getClient(getTaskRepository()).getSpaceById(spaceId, getTaskRepository());
internalSetAttributeOptions4Space(attribute, actualSpace.getMapFor(attribute.getId()));
}
} else {
attribute.clearOptions();
for (String spaceName : spaceAttribute.getValues()) {
Space actualSpace = repositoryConfiguration.getSpaceWithName(spaceName);
internalSetAttributeOptions4Space(attribute, actualSpace.getMapFor(attribute.getId()));
}
if (attribute.getOptions().size() == 0) {
if (attribute.getId().equals(taskSchema.ASSIGNEES.getKey())) {
String userName = repositoryConfiguration.getUserName();
attribute.putOption(userName, userName);
}
}
}
}
} catch (CoreException e) {
StatusHandler.log(new RepositoryStatus(getTaskRepository(), IStatus.ERROR, OSIORestCore.ID_PLUGIN, 0, "Failed to obtain repository configuration", // $NON-NLS-1$
e));
}
}
return super.getOptions(attribute);
}
Aggregations