use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class OrganizationStatePreloader method getStateJson.
@Override
public String getStateJson() {
BlueOrganization organization = Iterables.getFirst(OrganizationFactory.getInstance().list(), null);
if (organization != null) {
// default is root group
String organizationGroup = "/";
if (organization instanceof AbstractOrganization) {
organizationGroup = "/" + ((AbstractOrganization) organization).getGroup().getFullName();
}
StringWriter writer = new StringWriter();
new JSONBuilder(writer).object().key("name").value(organization.getName()).key("displayName").value(organization.getDisplayName()).key("organizationGroup").value(organizationGroup).endObject();
return writer.toString();
} else {
// if will happen only when there is no implementation of BlueOrganization found.
return "{}";
}
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class BranchContainerImpl method iterator.
@Override
@SuppressWarnings("unchecked")
public Iterator<BluePipeline> iterator(int start, int limit) {
final BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(pipeline.mbp.getItemGroup());
if (organization == null) {
throw new ServiceException.UnexpectedErrorException("Could not find organization for " + pipeline.mbp.getFullName());
}
final Link link = getLink();
// Filter will decide if the requester wants branches or pull requests
Collection allJobsMatchinFilter = ContainerFilter.filter(pipeline.mbp.getAllJobs());
// Transform all of these to branches (these represent branches or pull requests)
Iterable<BluePipeline> branches = Iterables.transform(allJobsMatchinFilter, new Function<Job, BluePipeline>() {
@Override
public BluePipeline apply(Job input) {
return new BranchImpl(organization, input, link);
}
});
// Order them using the comparator
branches = Ordering.from(BRANCH_COMPARATOR).sortedCopy(branches);
// Return the page requested by the client
return Iterables.limit(Iterables.skip(branches, start), limit).iterator();
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class BranchContainerImpl method get.
// TODO: implement rest of the methods
@Override
public BluePipeline get(String name) {
Job job = pipeline.mbp.getItem(name);
if (job == null) {
return null;
}
BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(job);
if (organization == null) {
return null;
}
return new BranchImpl(organization, job, getLink());
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class CredentialContainer method iterator.
@Override
public Iterator<CredentialApi> iterator() {
List<CredentialApi> apis = new ArrayList<>();
User user = User.current();
if (user != null) {
for (CredentialsStore store : CredentialsProvider.lookupStores(user)) {
if (store.getStoreAction() != null) {
apis.add(new CredentialApi(store.getStoreAction(), this));
}
}
} else {
Iterator<BlueOrganization> iterator = OrganizationFactory.getInstance().list().iterator();
BlueOrganization organization = iterator.hasNext() ? iterator.next() : null;
if (organization != null) {
ModifiableTopLevelItemGroup itemGroup = OrganizationFactory.getItemGroup(organization.getName());
for (CredentialsStore store : CredentialsProvider.lookupStores(itemGroup)) {
if (store.getStoreAction() != null) {
apis.add(new CredentialApi(store.getStoreAction(), this));
}
}
}
}
return apis.iterator();
}
use of io.jenkins.blueocean.rest.model.BlueOrganization in project blueocean-plugin by jenkinsci.
the class CredentialSearch method getOrganization.
private BlueOrganization getOrganization(Query q) {
String org = q.param("organization");
if (org == null) {
throw new ServiceException.BadRequestException("Credentials search query parameter 'organization' is required");
}
BlueOrganization organization = OrganizationFactory.getInstance().get(org);
if (organization == null) {
throw new ServiceException.BadRequestException(String.format("Organization %s not found. Query parameter 'organization' value: %s is invalid. ", org, org));
}
return organization;
}
Aggregations