public QueryResult<Group> syncGroupWith(String studyStr, String groupId, Group.Sync syncedFrom, String sessionId)
throws CatalogException {
ParamUtils.checkObj(syncedFrom, "sync");
String userId = catalogManager.getUserManager().getUserId(sessionId);
Study study = resolveId(studyStr, userId);
if (StringUtils.isEmpty(groupId)) {
throw new CatalogException("Missing group name parameter");
}
if (!groupId.startsWith("@")) {
groupId = "@" + groupId;
}
authorizationManager.checkSyncGroupPermissions(study.getUid(), userId, groupId);
QueryResult<Group> group = studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList());
if (group.first().getSyncedFrom() != null && StringUtils.isNotEmpty(group.first().getSyncedFrom().getAuthOrigin())
&& StringUtils.isNotEmpty(group.first().getSyncedFrom().getRemoteGroup())) {
throw new CatalogException("Cannot modify already existing sync information.");
}
Query query = new Query()
.append(StudyDBAdaptor.QueryParams.UID.key(), study.getUid())
.append(StudyDBAdaptor.QueryParams.GROUP_NAME.key(), groupId);
if (studyDBAdaptor.count(query).first() == 0) {
throw new CatalogException("The group " + groupId + " does not exist.");
}
studyDBAdaptor.syncGroup(study.getUid(), groupId, syncedFrom);
return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList());
}