use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class FavoritesStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
User jenkinsUser = User.current();
if (jenkinsUser != null) {
BlueOrganization organization = Iterables.getFirst(OrganizationFactory.getInstance().list(), null);
if (organization != null) {
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
// don't need this list when at pipeline pages
if (pipelineFullName != null) {
return null;
}
UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
if (favoritesContainer != null) {
JSONArray favorites = new JSONArray();
// Limit the number of favorites to return to a sane amount
Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);
while (favoritesIterator.hasNext()) {
Reachable favorite = favoritesIterator.next();
try {
favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
return null;
}
}
return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
}
}
}
// Don't preload any data on the page.
return null;
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class BlueMessageEnricher method maybeEnrichMessage.
private void maybeEnrichMessage(@Nonnull Message message) {
String channelName = message.getChannelName();
if (channelName.equals(Events.JobChannel.NAME) && message instanceof JobChannelMessage) {
JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
Item jobChannelItem = jobChannelMessage.getJobChannelItem();
if (jobChannelItem == null) {
return;
}
Link jobUrl = LinkResolver.resolveLink(jobChannelItem);
if (jobUrl == null) {
return;
}
BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(jobChannelItem);
if (org != null) {
message.set(EventProps.Jenkins.jenkins_org, org.getName());
}
jobChannelMessage.set(BlueEventProps.blueocean_job_rest_url, jobUrl.getHref());
jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, AbstractPipelineImpl.getFullName(org, jobChannelItem));
if (jobChannelItem instanceof WorkflowJob) {
ItemGroup<? extends Item> parent = jobChannelItem.getParent();
if (parent instanceof WorkflowMultiBranchProject) {
String multiBranchProjectName = AbstractPipelineImpl.getFullName(org, (WorkflowMultiBranchProject) parent);
jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, multiBranchProjectName);
jobChannelMessage.set(BlueEventProps.blueocean_job_branch_name, jobChannelItem.getName());
}
}
if (message.containsKey("job_run_queueId") && jobChannelItem instanceof hudson.model.Job) {
String queueIdStr = message.get("job_run_queueId");
if (queueIdStr == null) {
return;
}
final long queueId = Long.parseLong(queueIdStr);
Queue.Item queueItem = Jenkins.getInstance().getQueue().getItem(queueId);
if (queueItem == null) {
return;
}
hudson.model.Job job = (hudson.model.Job) jobChannelItem;
BlueQueueItem blueQueueItem = QueueUtil.getQueuedItem(null, queueItem, job);
if (blueQueueItem != null) {
jobChannelMessage.set(BlueEventProps.blueocean_queue_item_expected_build_number, Integer.toString(blueQueueItem.getExpectedBuildNumber()));
} else {
// If build is already running, we simply take the run id and pass it on
if (message.get("job_run_status") != null) {
String buildNumberStr = message.get("jenkins_object_id");
if (StringUtils.isNotBlank(buildNumberStr)) {
jobChannelMessage.set(BlueEventProps.blueocean_queue_item_expected_build_number, message.get("jenkins_object_id"));
}
}
}
}
}
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class CredentialSearch method search.
@Override
public Pageable<CredentialApi.Credential> search(Query q) {
List<CredentialApi.Credential> credentials = new ArrayList<>();
String domain = q.param("domain");
String store = q.param("store");
BlueOrganization organization = getOrganization(q);
CredentialContainer credentialContainer = new CredentialContainer(organization.getLink());
for (CredentialApi api : credentialContainer) {
if (store != null && !store.equals(api.getStore())) {
continue;
}
if (domain != null) {
CredentialApi.CredentialDomain d = api.getDomains().get(domain);
if (d == null) {
throw new ServiceException.BadRequestException("Credential domain " + domain + " not found");
}
for (CredentialApi.Credential c : d.getCredentials()) {
credentials.add(c);
}
} else {
for (CredentialApi.CredentialDomain d : api.getDomains()) {
for (CredentialApi.Credential c : d.getCredentials()) {
credentials.add(c);
}
}
}
}
return Pageables.wrap(credentials);
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method mockOrganization.
static BlueOrganization mockOrganization() {
BlueOrganization organization = mock(BlueOrganization.class);
when(organization.getName()).thenReturn("jenkins");
when(organization.getLink()).thenReturn(new Link("/blue/rest/organizations/jenkins/"));
return organization;
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class RunSearch method getLatestRun.
private BlueRun getLatestRun(Job job) {
if (job == null) {
return null;
}
BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(job);
if (org == null) {
return null;
}
Run r = job.getLastBuild();
if (r == null) {
return null;
}
Resource resource = BluePipelineFactory.resolve(job);
if (resource == null) {
return null;
}
return BlueRunFactory.getRun(r, resource);
}
Aggregations