98 lines
3.0 KiB
Java
98 lines
3.0 KiB
Java
package io.jenkins.blueocean.service.embedded.rest;
|
|
|
|
import hudson.model.User;
|
|
import io.jenkins.blueocean.commons.ServiceException;
|
|
import io.jenkins.blueocean.commons.stapler.JsonBody;
|
|
import io.jenkins.blueocean.rest.ApiHead;
|
|
import io.jenkins.blueocean.rest.hal.Link;
|
|
import io.jenkins.blueocean.rest.model.BlueOrganization;
|
|
import io.jenkins.blueocean.rest.model.BluePipelineContainer;
|
|
import io.jenkins.blueocean.rest.model.BlueUser;
|
|
import io.jenkins.blueocean.rest.model.BlueUserContainer;
|
|
import jenkins.model.Jenkins;
|
|
import org.jenkinsci.plugins.jenkinsorganizations.JenkinsOrganizationFolder;
|
|
import org.kohsuke.stapler.WebMethod;
|
|
import org.kohsuke.stapler.verb.DELETE;
|
|
import org.kohsuke.stapler.verb.PUT;
|
|
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* {@link BlueOrganization} implementation for the embedded use.
|
|
*
|
|
* @author Vivek Pandey
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
public class OrganizationImpl extends BlueOrganization {
|
|
private final UserContainerImpl users = new UserContainerImpl(this);
|
|
final JenkinsOrganizationFolder organizationFolder;
|
|
/**
|
|
* In embedded mode, there's only one organization
|
|
*/
|
|
public static final OrganizationImpl DEFAULT_ORGANIZATION = new OrganizationImpl();
|
|
public OrganizationImpl(JenkinsOrganizationFolder organizationFolder) {
|
|
this.organizationFolder = organizationFolder;
|
|
}
|
|
|
|
private OrganizationImpl() {
|
|
this(null);
|
|
}
|
|
|
|
/**
|
|
* In embedded mode, there's only one organization
|
|
*/
|
|
public String getName() {
|
|
if(organizationFolder == null) {
|
|
return Jenkins.getInstance().getDisplayName().toLowerCase();
|
|
} else {
|
|
return organizationFolder.getDisplayName();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BluePipelineContainer getPipelines() {
|
|
return new PipelineContainerImpl(Jenkins.getInstance());
|
|
}
|
|
|
|
@WebMethod(name="") @DELETE
|
|
public void delete() {
|
|
throw new ServiceException.NotImplementedException("Not implemented yet");
|
|
}
|
|
|
|
@WebMethod(name="") @PUT
|
|
public void update(@JsonBody OrganizationImpl given) throws IOException {
|
|
given.validate();
|
|
throw new ServiceException.NotImplementedException("Not implemented yet");
|
|
// getXmlFile().write(given);
|
|
}
|
|
|
|
private void validate() {
|
|
// if (name.length()<2)
|
|
// throw new IllegalArgumentException("Invalid name: "+name);
|
|
}
|
|
|
|
/**
|
|
* In the embedded case, there's only one organization and everyone belongs there,
|
|
* so we can just return that singleton.
|
|
*/
|
|
@Override
|
|
public BlueUserContainer getUsers() {
|
|
return users;
|
|
}
|
|
|
|
@Override
|
|
public BlueUser getUser() {
|
|
User user = User.current();
|
|
if(user == null){
|
|
throw new ServiceException.NotFoundException("No authenticated user found");
|
|
}
|
|
return new UserImpl(user,new UserContainerImpl(OrganizationImpl.DEFAULT_ORGANIZATION));
|
|
}
|
|
|
|
@Override
|
|
public Link getLink() {
|
|
return ApiHead.INSTANCE().getLink().rel("organizations/"+getName());
|
|
}
|
|
|
|
}
|