use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData in project intellij-tekton by redhat-developer.
the class HubModel method getInstalledHubItems.
public List<HubItem> getInstalledHubItems() {
List<HubItem> items = new ArrayList<>();
List<HasMetadata> hubItemsAlreadyInstalled = getAllInstalledHubItems();
List<ResourceData> resourceDataList = retrieveAllResources();
for (HasMetadata task : hubItemsAlreadyInstalled) {
Optional<HubItem> hubItem = resourceDataList.stream().filter(resourceData -> resourceData.getName().equalsIgnoreCase(task.getMetadata().getName())).map(resourceData -> {
String version = task.getMetadata().getLabels() != null ? task.getMetadata().getLabels().get(APP_K8S_IO_VERSION) : "";
if (!version.isEmpty()) {
return new HubItem(resourceData, task.getKind(), version);
} else {
return new HubItem(resourceData);
}
}).findFirst();
hubItem.ifPresent(items::add);
}
return items;
}
use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData in project intellij-tekton by redhat-developer.
the class HubDetailsPageComponent method show.
public void show(HubItem item, TriConsumer<HubItem, String, String> doInstallAction) {
if (item == null) {
select(1, true);
} else {
ResourceData resource = item.getResource();
ResourceVersionData resourceVersionData = getHubItemResourceVersionData(item);
if (resourceVersionData == null) {
return;
}
setInstallButtons(item, doInstallAction);
setNameLabel(resourceVersionData, resource.getName());
fillVersionsCombo(resource, resourceVersionData);
myRating.setText(resource.getRating().toString());
myHomePage.show(resource.getKind() + " Homepage", () -> {
try {
Desktop.getDesktop().browse(resourceVersionData.getWebURL());
} catch (IOException e) {
logger.warn(e.getLocalizedMessage(), e);
}
});
setDetailsPanel(resource, resourceVersionData);
loadBottomTabs(resource.getName(), resourceVersionData.getRawURL());
select(0, true);
}
}
use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData in project intellij-tekton by redhat-developer.
the class HubItemScoreTest method buildHubItem.
private HubItem buildHubItem(String name, String description, List<Tag> tags) {
ResourceData resourceData = mock(ResourceData.class);
ResourceVersionData resourceVersionData = mock(ResourceVersionData.class);
when(resourceData.getLatestVersion()).thenReturn(resourceVersionData);
when(resourceVersionData.getVersion()).thenReturn("v1");
when(resourceVersionData.getDescription()).thenReturn(description);
when(resourceData.getName()).thenReturn(name);
when(resourceData.getKind()).thenReturn("kind");
when(resourceData.getTags()).thenReturn(tags);
HubItem hubItem = new HubItem(resourceData);
return hubItem;
}
use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData in project intellij-tekton by redhat-developer.
the class HubItemPanelsBoard method installHubItem.
private void installHubItem(HubItem hubItem, String kindToBeSaved, String version) {
ResourceData resource = hubItem.getResource();
scrollContentPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR));
ExecHelper.submit(() -> {
try {
Constants.InstallStatus installed = model.installHubItem(resource.getName(), kindToBeSaved, version, resource.getCatalog().getName());
UIHelper.executeInUI(() -> {
if (installed != Constants.InstallStatus.ERROR) {
NotificationHelper.notify(model.getProject(), "Save Successful", resource.getKind() + " " + resource.getName() + " has been saved!", NotificationType.INFORMATION, true);
}
});
} catch (IOException ex) {
UIHelper.executeInUI(() -> NotificationHelper.notify(model.getProject(), "Error", "An error occurred while saving " + resource.getKind() + " " + resource.getName() + "\n" + ex.getLocalizedMessage(), NotificationType.ERROR, false));
}
UIHelper.executeInUI(() -> {
scrollContentPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
});
});
}
use of com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData in project intellij-tekton by redhat-developer.
the class HubItemScore method computeScore.
private int computeScore(HubItem hubItem) {
int score = 0;
ResourceData resourceData = hubItem.getResource();
ResourceVersionData resourceVersionData = resourceData.getLatestVersion();
for (int i = 0; i < languages.size(); i++) {
Language language = languages.get(i);
int multiplier = i >= LANGUAGES_MULTIPLIER.length ? LANGUAGES_MULTIPLIER[LANGUAGES_MULTIPLIER.length - 1] : LANGUAGES_MULTIPLIER[i];
if (matches(resourceData.getName(), language)) {
score += NAME_WEIGHT * multiplier;
}
if (resourceVersionData != null && matches(resourceVersionData.getDescription(), language)) {
score += DESCRIPTION_WEIGHT * multiplier;
}
List<String> tags = resourceData.getTags().stream().map(c -> c.getName()).collect(Collectors.toList());
if (resourceData.getTags().contains(language.getName()) || matches(tags, language)) {
score += TAG_WEIGHT * multiplier;
}
}
return score;
}
Aggregations