use of hudson.model.ItemGroup in project blueocean-plugin by jenkinsci.
the class AbstractPipelineCreateRequestImpl method create.
@Nonnull
public TopLevelItem create(ModifiableTopLevelItemGroup parent, String name, String descriptorName, Class<? extends TopLevelItemDescriptor> descriptorClass) throws IOException {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CREATE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to create pipeline: %s. User %s doesn't have Job create permission", name, a.getName()));
}
TopLevelItemDescriptor descriptor = Items.all().findByName(descriptorName);
if (descriptor == null || !(descriptorClass.isAssignableFrom(descriptor.getClass()))) {
throw new ServiceException.BadRequestExpception(String.format("Failed to create pipeline: %s, descriptor %s is not found", name, descriptorName));
}
ItemGroup p = Jenkins.getInstance();
if (!descriptor.isApplicableIn(p)) {
throw new ServiceException.ForbiddenException(String.format("Failed to create pipeline: %s. pipeline can't be created in Jenkins root folder", name));
}
if (!acl.hasCreatePermission(a, p, descriptor)) {
throw new ServiceException.ForbiddenException("Missing permission: " + Item.CREATE.group.title + "/" + Item.CREATE.name + Item.CREATE + "/" + descriptor.getDisplayName());
}
return parent.createProject(descriptor, name, true);
}
use of hudson.model.ItemGroup in project blueocean-plugin by jenkinsci.
the class BlueOceanWebURLBuilder method getPipelineModelMapping.
private static BlueOceanModelMapping getPipelineModelMapping(Job job) {
BluePipeline blueResource = (BluePipeline) BluePipelineFactory.resolve(job);
if (blueResource instanceof BranchImpl) {
// No abstract "Branch" type?
ItemGroup multibranchJob = job.getParent();
BluePipeline multibranchJobResource = (BluePipeline) BluePipelineFactory.resolve((Item) multibranchJob);
return new BlueOceanModelMapping(multibranchJob, multibranchJobResource, getOrgPrefix() + "/" + encodeURIComponent(multibranchJobResource.getFullName()));
} else {
return new BlueOceanModelMapping(job, blueResource, getOrgPrefix() + "/" + encodeURIComponent(blueResource.getFullName()));
}
}
use of hudson.model.ItemGroup in project blueocean-plugin by jenkinsci.
the class LinkResolverImpl method resolve.
@Override
public Link resolve(Object modelObject) {
if (modelObject instanceof Job) {
Resource resource = resolveJob((Job) modelObject);
if (resource != null) {
return resource.getLink();
}
} else if (modelObject instanceof Item && modelObject instanceof ItemGroup) {
Resource resource = resolveFolder((Item) modelObject);
if (resource != null) {
return resource.getLink();
}
} else if (modelObject instanceof Run) {
Run run = (Run) modelObject;
Resource resource = resolveRun(run);
if (resource != null) {
return resource.getLink();
}
}
return null;
}
use of hudson.model.ItemGroup in project hubot-steps-plugin by jenkinsci.
the class HubotSite method get.
public static HubotSite get(final Job<?, ?> job, final TaskListener listener, final String siteName) {
HubotSite hubotSite = null;
HubotSite defaultSite = null;
ItemGroup parent = job.getParent();
String folderName = null;
// Site from folder(s).
try {
while (parent != null) {
if (parent instanceof AbstractFolder) {
AbstractFolder folder = (AbstractFolder) parent;
if (folderName == null) {
folderName = folder.getName();
}
HubotFolderProperty jfp = (HubotFolderProperty) folder.getProperties().get(HubotFolderProperty.class);
if (jfp != null) {
HubotSite[] sites = jfp.getSites();
if (sites != null && sites.length > 0) {
for (HubotSite site : sites) {
HubotSite cloneSite = site.clone();
if (cloneSite.isUseFolderName()) {
cloneSite.setRoom(folder.getName());
}
if (siteName != null) {
if (cloneSite.getName().equalsIgnoreCase(siteName) && hubotSite == null) {
hubotSite = cloneSite;
}
} else {
if (cloneSite.isDefaultSite() && defaultSite == null) {
defaultSite = cloneSite;
}
}
}
}
}
}
if (parent instanceof Item) {
parent = ((Item) parent).getParent();
} else {
parent = null;
}
}
// Global Sites.
if (hubotSite == null && defaultSite == null) {
for (HubotSite site : new GlobalConfig().getSites()) {
HubotSite cloneSite = site.clone();
if (site.isUseFolderName()) {
if (folderName != null) {
cloneSite.setRoom(folderName);
}
}
if (siteName != null) {
if (cloneSite.getName().equalsIgnoreCase(siteName) && hubotSite == null) {
hubotSite = cloneSite;
}
} else {
if (cloneSite.isDefaultSite() && defaultSite == null) {
defaultSite = cloneSite;
}
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to get hubot site", e);
}
return hubotSite == null ? defaultSite : hubotSite;
}
Aggregations