Remove old RPCs to get project details and to update project settings

These old RPCs are not used anymore. Their functionality is available
over REST.

The visibleProjectDetails RPC was done for the Mylyn Gerrit Connector
to find project details for all projects but permission only projects.

The REST endpoint to list projects does support to filter out
permission only projects so the Gerrit Mylyn Connector can implement
its functionality on REST.

Change-Id: Ie83e9021b564faa401fc0f6405fdd8621d6b7b6f
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2013-07-17 13:42:45 +02:00 committed by David Pursehouse
parent 7800186ac1
commit 984781e9bb
7 changed files with 1 additions and 411 deletions

View File

@ -27,19 +27,9 @@ import java.util.List;
@RpcImpl(version = Version.V2_0) @RpcImpl(version = Version.V2_0)
public interface ProjectAdminService extends RemoteJsonService { public interface ProjectAdminService extends RemoteJsonService {
void visibleProjectDetails(AsyncCallback<List<ProjectDetail>> callback);
void projectDetail(Project.NameKey projectName,
AsyncCallback<ProjectDetail> callback);
void projectAccess(Project.NameKey projectName, void projectAccess(Project.NameKey projectName,
AsyncCallback<ProjectAccess> callback); AsyncCallback<ProjectAccess> callback);
@Audit
@SignInRequired
void changeProjectSettings(Project update,
AsyncCallback<ProjectDetail> callback);
@Audit @Audit
@SignInRequired @SignInRequired
void changeProjectAccess(Project.NameKey projectName, String baseRevision, void changeProjectAccess(Project.NameKey projectName, String baseRevision,

View File

@ -1,84 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.common.data;
import com.google.gerrit.reviewdb.client.InheritedBoolean;
import com.google.gerrit.reviewdb.client.Project;
public class ProjectDetail {
public Project project;
public boolean canModifyDescription;
public boolean canModifyMergeType;
public boolean canModifyAgreements;
public boolean canModifyAccess;
public boolean canModifyState;
public boolean canModifyMaxObjectSizeLimit;
public boolean isPermissionOnly;
public InheritedBoolean useContributorAgreements;
public InheritedBoolean useSignedOffBy;
public InheritedBoolean useContentMerge;
public InheritedBoolean requireChangeID;
public ProjectDetail() {
}
public void setProject(final Project p) {
project = p;
}
public void setCanModifyDescription(final boolean cmd) {
canModifyDescription = cmd;
}
public void setCanModifyMergeType(final boolean cmmt) {
canModifyMergeType = cmmt;
}
public void setCanModifyState(final boolean cms) {
canModifyState = cms;
}
public void setCanModifyMaxObjectSizeLimit(final boolean cmmosl) {
canModifyMaxObjectSizeLimit = cmmosl;
}
public void setCanModifyAgreements(final boolean cma) {
canModifyAgreements = cma;
}
public void setCanModifyAccess(final boolean cma) {
canModifyAccess = cma;
}
public void setPermissionOnly(final boolean ipo) {
isPermissionOnly = ipo;
}
public void setUseContributorAgreements(final InheritedBoolean uca) {
useContributorAgreements = uca;
}
public void setUseSignedOffBy(final InheritedBoolean usob) {
useSignedOffBy = usob;
}
public void setUseContentMerge(final InheritedBoolean ucm) {
useContentMerge = ucm;
}
public void setRequireChangeID(final InheritedBoolean rcid) {
requireChangeID = rcid;
}
}

View File

@ -1,106 +0,0 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.httpd.rpc.project;
import com.google.gerrit.common.data.ProjectDetail;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.PerRequestProjectControlCache;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gwtorm.server.OrmConcurrencyException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import java.io.IOException;
class ChangeProjectSettings extends Handler<ProjectDetail> {
interface Factory {
ChangeProjectSettings create(@Assisted Project update);
}
private final ProjectDetailFactory.Factory projectDetailFactory;
private final ProjectControl.Factory projectControlFactory;
private final GitRepositoryManager mgr;
private final MetaDataUpdate.User metaDataUpdateFactory;
private final Provider<PerRequestProjectControlCache> userCache;
private final Project update;
@Inject
ChangeProjectSettings(
final ProjectDetailFactory.Factory projectDetailFactory,
final ProjectControl.Factory projectControlFactory,
final GitRepositoryManager mgr,
final MetaDataUpdate.User metaDataUpdateFactory,
final Provider<PerRequestProjectControlCache> uc,
@Assisted final Project update) {
this.projectDetailFactory = projectDetailFactory;
this.projectControlFactory = projectControlFactory;
this.mgr = mgr;
this.userCache = uc;
this.metaDataUpdateFactory = metaDataUpdateFactory;
this.update = update;
}
@Override
public ProjectDetail call() throws NoSuchProjectException, OrmException,
IOException {
final Project.NameKey projectName = update.getNameKey();
projectControlFactory.ownerFor(projectName);
final MetaDataUpdate md;
try {
md = metaDataUpdateFactory.create(projectName);
} catch (RepositoryNotFoundException notFound) {
throw new NoSuchProjectException(projectName);
} catch (IOException e) {
throw new OrmException(e);
}
try {
// TODO We really should take advantage of the Git commit DAG and
// ensure the current version matches the old version the caller read.
//
ProjectConfig config = ProjectConfig.read(md);
config.getProject().copySettingsFrom(update);
md.setMessage("Modified project settings\n");
try {
config.commit(md);
mgr.setProjectDescription(projectName, update.getDescription());
userCache.get().evict(config.getProject());
} catch (IOException e) {
throw new OrmConcurrencyException("Cannot update " + projectName);
}
} catch (ConfigInvalidException err) {
throw new OrmException("Cannot read project " + projectName, err);
} catch (IOException err) {
throw new OrmException("Cannot update project " + projectName, err);
} finally {
md.close();
}
return projectDetailFactory.create(projectName).call();
}
}

View File

@ -17,7 +17,6 @@ package com.google.gerrit.httpd.rpc.project;
import com.google.gerrit.common.data.AccessSection; import com.google.gerrit.common.data.AccessSection;
import com.google.gerrit.common.data.ProjectAccess; import com.google.gerrit.common.data.ProjectAccess;
import com.google.gerrit.common.data.ProjectAdminService; import com.google.gerrit.common.data.ProjectAdminService;
import com.google.gerrit.common.data.ProjectDetail;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.AsyncCallback;
@ -30,35 +29,15 @@ import java.util.List;
class ProjectAdminServiceImpl implements ProjectAdminService { class ProjectAdminServiceImpl implements ProjectAdminService {
private final ChangeProjectAccess.Factory changeProjectAccessFactory; private final ChangeProjectAccess.Factory changeProjectAccessFactory;
private final ReviewProjectAccess.Factory reviewProjectAccessFactory; private final ReviewProjectAccess.Factory reviewProjectAccessFactory;
private final ChangeProjectSettings.Factory changeProjectSettingsFactory;
private final VisibleProjectDetails.Factory visibleProjectDetailsFactory;
private final ProjectAccessFactory.Factory projectAccessFactory; private final ProjectAccessFactory.Factory projectAccessFactory;
private final ProjectDetailFactory.Factory projectDetailFactory;
@Inject @Inject
ProjectAdminServiceImpl(final ChangeProjectAccess.Factory changeProjectAccessFactory, ProjectAdminServiceImpl(final ChangeProjectAccess.Factory changeProjectAccessFactory,
final ReviewProjectAccess.Factory reviewProjectAccessFactory, final ReviewProjectAccess.Factory reviewProjectAccessFactory,
final ChangeProjectSettings.Factory changeProjectSettingsFactory, final ProjectAccessFactory.Factory projectAccessFactory) {
final VisibleProjectDetails.Factory visibleProjectDetailsFactory,
final ProjectAccessFactory.Factory projectAccessFactory,
final ProjectDetailFactory.Factory projectDetailFactory) {
this.changeProjectAccessFactory = changeProjectAccessFactory; this.changeProjectAccessFactory = changeProjectAccessFactory;
this.reviewProjectAccessFactory = reviewProjectAccessFactory; this.reviewProjectAccessFactory = reviewProjectAccessFactory;
this.changeProjectSettingsFactory = changeProjectSettingsFactory;
this.visibleProjectDetailsFactory = visibleProjectDetailsFactory;
this.projectAccessFactory = projectAccessFactory; this.projectAccessFactory = projectAccessFactory;
this.projectDetailFactory = projectDetailFactory;
}
@Override
public void visibleProjectDetails(final AsyncCallback<List<ProjectDetail>> callback) {
visibleProjectDetailsFactory.create().to(callback);
}
@Override
public void projectDetail(final Project.NameKey projectName,
final AsyncCallback<ProjectDetail> callback) {
projectDetailFactory.create(projectName).to(callback);
} }
@Override @Override
@ -67,12 +46,6 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
projectAccessFactory.create(projectName).to(callback); projectAccessFactory.create(projectName).to(callback);
} }
@Override
public void changeProjectSettings(final Project update,
final AsyncCallback<ProjectDetail> callback) {
changeProjectSettingsFactory.create(update).to(callback);
}
private static ObjectId getBase(final String baseRevision) { private static ObjectId getBase(final String baseRevision) {
if (baseRevision != null && !baseRevision.isEmpty()) { if (baseRevision != null && !baseRevision.isEmpty()) {
return ObjectId.fromString(baseRevision); return ObjectId.fromString(baseRevision);

View File

@ -1,117 +0,0 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.httpd.rpc.project;
import com.google.common.collect.Iterables;
import com.google.gerrit.common.data.ProjectDetail;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.client.InheritedBoolean;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.ProjectState;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import java.io.IOException;
class ProjectDetailFactory extends Handler<ProjectDetail> {
interface Factory {
ProjectDetailFactory create(@Assisted Project.NameKey name);
}
private final ProjectControl.Factory projectControlFactory;
private final GitRepositoryManager gitRepositoryManager;
private final Project.NameKey projectName;
@Inject
ProjectDetailFactory(final ProjectControl.Factory projectControlFactory,
final GitRepositoryManager gitRepositoryManager,
@Assisted final Project.NameKey name) {
this.projectControlFactory = projectControlFactory;
this.gitRepositoryManager = gitRepositoryManager;
this.projectName = name;
}
@Override
public ProjectDetail call() throws NoSuchProjectException, IOException {
final ProjectControl pc =
projectControlFactory.validateFor(projectName, ProjectControl.OWNER
| ProjectControl.VISIBLE);
final ProjectState projectState = pc.getProjectState();
final ProjectDetail detail = new ProjectDetail();
detail.setProject(projectState.getProject());
final boolean userIsOwner = pc.isOwner();
final boolean userIsOwnerAnyRef = pc.isOwnerAnyRef();
detail.setCanModifyAccess(userIsOwnerAnyRef);
detail.setCanModifyAgreements(userIsOwner);
detail.setCanModifyDescription(userIsOwner);
detail.setCanModifyMergeType(userIsOwner);
detail.setCanModifyState(userIsOwner);
detail.setCanModifyMaxObjectSizeLimit(userIsOwner);
final InheritedBoolean useContributorAgreements = new InheritedBoolean();
final InheritedBoolean useSignedOffBy = new InheritedBoolean();
final InheritedBoolean useContentMerge = new InheritedBoolean();
final InheritedBoolean requireChangeID = new InheritedBoolean();
useContributorAgreements.setValue(projectState.getProject()
.getUseContributorAgreements());
useSignedOffBy.setValue(projectState.getProject().getUseSignedOffBy());
useContentMerge.setValue(projectState.getProject().getUseContentMerge());
requireChangeID.setValue(projectState.getProject().getRequireChangeID());
ProjectState parentState = Iterables.getFirst(projectState.parents(), null);
if (parentState != null) {
useContributorAgreements.setInheritedValue(parentState
.isUseContributorAgreements());
useSignedOffBy.setInheritedValue(parentState.isUseSignedOffBy());
useContentMerge.setInheritedValue(parentState.isUseContentMerge());
requireChangeID.setInheritedValue(parentState.isRequireChangeID());
}
detail.setUseContributorAgreements(useContributorAgreements);
detail.setUseSignedOffBy(useSignedOffBy);
detail.setUseContentMerge(useContentMerge);
detail.setRequireChangeID(requireChangeID);
final Project.NameKey projectName = projectState.getProject().getNameKey();
Repository git;
try {
git = gitRepositoryManager.openRepository(projectName);
} catch (RepositoryNotFoundException err) {
throw new NoSuchProjectException(projectName);
}
try {
Ref head = git.getRef(Constants.HEAD);
if (head != null && head.isSymbolic()
&& GitRepositoryManager.REF_CONFIG.equals(head.getLeaf().getName())) {
detail.setPermissionOnly(true);
}
} catch (IOException err) {
throw new NoSuchProjectException(projectName);
} finally {
git.close();
}
return detail;
}
}

View File

@ -30,10 +30,7 @@ public class ProjectModule extends RpcServletModule {
protected void configure() { protected void configure() {
factory(ChangeProjectAccess.Factory.class); factory(ChangeProjectAccess.Factory.class);
factory(ReviewProjectAccess.Factory.class); factory(ReviewProjectAccess.Factory.class);
factory(ChangeProjectSettings.Factory.class);
factory(VisibleProjectDetails.Factory.class);
factory(ProjectAccessFactory.Factory.class); factory(ProjectAccessFactory.Factory.class);
factory(ProjectDetailFactory.Factory.class);
} }
}); });
rpc(ProjectAdminServiceImpl.class); rpc(ProjectAdminServiceImpl.class);

View File

@ -1,63 +0,0 @@
// Copyright (C) 2011 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.httpd.rpc.project;
import com.google.gerrit.common.data.ProjectDetail;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
class VisibleProjectDetails extends Handler<List<ProjectDetail>> {
interface Factory {
VisibleProjectDetails create();
}
private final ProjectCache projectCache;
private final ProjectDetailFactory.Factory projectDetailFactory;
@Inject
VisibleProjectDetails(final ProjectCache projectCache,
final ProjectDetailFactory.Factory projectDetailFactory) {
this.projectCache = projectCache;
this.projectDetailFactory = projectDetailFactory;
}
@Override
public List<ProjectDetail> call() {
List<ProjectDetail> result = new ArrayList<ProjectDetail>();
for (Project.NameKey projectName : projectCache.all()) {
try {
result.add(projectDetailFactory.create(projectName).call());
} catch (NoSuchProjectException e) {
} catch (IOException e) {
}
}
Collections.sort(result, new Comparator<ProjectDetail>() {
public int compare(final ProjectDetail a, final ProjectDetail b) {
return a.project.getName().compareTo(b.project.getName());
}
});
return result;
}
}