net.nemerosa.ontrack.model.structure.Branch类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中net.nemerosa.ontrack.model.structure.Branch类的一些代码示例,展示了Branch类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Branch类的具体详情如下:
包路径:net.nemerosa.ontrack.model.structure.Branch
类名称:Branch

Branch介绍

暂无

代码示例

代码示例来源:origin: net.nemerosa.ontrack/ontrack-extension-svn

@Override
public String getDescription() {
  return String.format(
      "Synchronisation of builds with SVN for branch %s/%s",
      branch.getProject().getName(),
      branch.getName()
  );
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-ui-graphql

private DataFetcher branchValidationStampsFetcher() {
  return environment -> {
    Object source = environment.getSource();
    Optional<String> name = GraphqlUtils.getStringArgument(environment, "name");
    if (source instanceof Branch) {
      Branch branch = (Branch) source;
      if (name.isPresent()) {
        return structureService.findValidationStampByName(
            branch.getProject().getName(), branch.getName(), name.get()
        )
            .map(Collections::singletonList)
            .orElse(Collections.emptyList());
      } else {
        return structureService.getValidationStampListForBranch(branch.getId());
      }
    } else {
      return Collections.emptyList();
    }
  };
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-extension-general

@Override
public List<Decoration<BranchType>> getDecorations(ProjectEntity entity) {
  if (entity instanceof Branch) {
    Branch branch = (Branch) entity;
    switch (branch.getType()) {
      case TEMPLATE_DEFINITION:
      case TEMPLATE_INSTANCE:
        return Collections.singletonList(
            Decoration.of(
                this,
                branch.getType()
            )
        );
      default:
        // No decoration by default
        return Collections.emptyList();
    }
  } else {
    return Collections.emptyList();
  }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-model

public Branch update(NameDescriptionState form) {
    return of(project, form).withId(id).withDisabled(form.isDisabled());
  }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-model

@Override
public boolean isDisabled() {
  return branch.isDisabled() || branch.getProject().isDisabled();
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

protected BranchTemplateSyncResult syncTemplateDefinition(Branch templateBranch, TemplateDefinition templateDefinition, String sourceName, JobRunListener listener) {
  listener.message("Sync. %s --> %s", templateBranch.getName(), sourceName);
      templateBranch.getProject().getName(),
      branchName);
    if (targetBranch.get().getType() == BranchType.CLASSIC) {
      return BranchTemplateSyncResult.existingClassic(branchName, sourceName);
    } else if (targetBranch.get().getType() == BranchType.TEMPLATE_DEFINITION) {
      return BranchTemplateSyncResult.existingDefinition(branchName, sourceName);
    } else {
      Optional<TemplateInstance> existingTemplateInstance = branchTemplateRepository.getTemplateInstance(targetBranch.get().getId());
      if (existingTemplateInstance.isPresent() && !existingTemplateInstance.get().getTemplateDefinitionId().equals(templateBranch.getId())) {
        return BranchTemplateSyncResult.existingInstanceFromOther(
            branchName,
            sourceName,
            structureService.getBranch(existingTemplateInstance.get().getTemplateDefinitionId()).getName()
        );
      } else {

代码示例来源:origin: net.nemerosa.ontrack/ontrack-repository-impl

@Override
public Branch newBranch(Branch branch) {
  // Creation
  try {
    int id = dbCreate(
        "INSERT INTO BRANCHES(PROJECTID, NAME, DESCRIPTION, DISABLED, CREATION, CREATOR) VALUES (:projectId, :name, :description, :disabled, :creation, :creator)",
        params("name", branch.getName())
            .addValue("description", branch.getDescription())
            .addValue("disabled", branch.isDisabled())
            .addValue("projectId", branch.getProject().id())
            .addValue("creation", dateTimeForDB(branch.getSignature().getTime()))
            .addValue("creator", branch.getSignature().getUser().getName())
    );
    // Returns with ID
    return branch.withId(id(id));
  } catch (DuplicateKeyException ex) {
    throw new BranchNameAlreadyDefinedException(branch.getName());
  }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-repository-impl

"BRANCHID = :branchId "
);
MapSqlParameterSource params = params("branchId", branch.id());
Integer fromId;
Integer toId = null;
fromId = structureRepository.getBuildByName(branch.getProject().getName(), branch.getName(), from)
    .orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), from))
    .id();
  toId = structureRepository.getBuildByName(branch.getProject().getName(), branch.getName(), to)
      .orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), to))
      .id();

代码示例来源:origin: net.nemerosa.ontrack/ontrack-model

@Override
public Project getProject() {
  return getBranch().getProject();
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

protected void doCopyUserBuildFilters(Branch sourceBranch, Branch targetBranch) {
  buildFilterService.copyToBranch(sourceBranch.getId(), targetBranch.getId());
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

protected BranchTemplateSyncResult applyMissingPolicy(Branch branch, TemplateSynchronisationAbsencePolicy absencePolicy) {
  if (branch.isDisabled()) {
    return BranchTemplateSyncResult.ignored(branch.getName());
  } else {
    switch (absencePolicy) {
      case DELETE:
        structureService.deleteBranch(branch.getId());
        return BranchTemplateSyncResult.deleted(branch.getName());
      case DISABLE:
      default:
        structureService.saveBranch(branch.withDisabled(true));
        return BranchTemplateSyncResult.disabled(branch.getName());
    }
  }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

@Override
public Branch copy(Branch targetBranch, Branch sourceBranch, Function<String, String> replacementFn, SyncPolicy syncPolicy) {
  // If same branch, rejects
  if (sourceBranch.id() == targetBranch.id()) {
    throw new CannotCopyItselfException();
  }
  // Checks the rights on the target branch
  securityService.checkProjectFunction(targetBranch, BranchEdit.class);
  // Now, we can work in a secure context
  securityService.asAdmin(() -> doCopy(sourceBranch, targetBranch, replacementFn, syncPolicy));
  // OK
  return targetBranch;
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

String branchName = NameDescription.escapeName(sourceName);
Optional<Branch> existingBranch = structureService.findBranchByName(
    branch.getProject().getName(),
    sourceName);
else if (existingBranch.get().getType() == BranchType.CLASSIC) {
  throw new BranchClassicCannotBeTemplateInstanceException(branchName);
else if (existingBranch.get().getType() == BranchType.TEMPLATE_DEFINITION) {
  throw new BranchTemplateDefinitionCannotBeTemplateInstanceException(branchName);
} else {
  Optional<TemplateInstance> templateInstanceOptional = branchTemplateRepository.getTemplateInstance(existingBranch.get().getId());
  if (!Objects.equals(linkedTemplateId, branch.getId())) {
    throw new BranchTemplateInstanceCannotUpdateBasedOnOtherDefinitionException(branchName);

代码示例来源:origin: net.nemerosa.ontrack/ontrack-repository-impl

@Override
public void saveBranch(Branch branch) {
  // Update
  try {
    getNamedParameterJdbcTemplate().update(
        "UPDATE BRANCHES SET NAME = :name, DESCRIPTION = :description, DISABLED = :disabled WHERE ID = :id",
        params("name", branch.getName())
            .addValue("description", branch.getDescription())
            .addValue("disabled", branch.isDisabled())
            .addValue("id", branch.id())
    );
  } catch (DuplicateKeyException ex) {
    throw new BranchNameAlreadyDefinedException(branch.getName());
  }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-repository-impl

@Override
public Optional<ValidationStampFilter> getValidationStampFilterByName(Branch branch, String name) {
  // Branch first
  Optional<ValidationStampFilter> o = getOptional(
      "SELECT * FROM VALIDATION_STAMP_FILTERS WHERE PROJECT IS NULL AND BRANCH = :branch AND NAME = :name",
      params("branch", branch.id()).addValue("name", name),
      (ResultSet rs, int rowNum) -> toValidationStampFilter(rs, pid -> null, bid -> branch)
  );
  // ... then project
  if (!o.isPresent()) {
    o = getOptional(
        "SELECT * FROM VALIDATION_STAMP_FILTERS WHERE PROJECT = :project AND BRANCH IS NULL AND NAME = :name",
        params("project", branch.getProject().id()).addValue("name", name),
        (ResultSet rs, int rowNum) -> toValidationStampFilter(rs, pid -> branch.getProject(), bid -> null)
    );
  }
  // ... the global
  if (!o.isPresent()) {
    o = getOptional(
        "SELECT * FROM VALIDATION_STAMP_FILTERS WHERE PROJECT IS NULL AND BRANCH IS NULL AND NAME = :name",
        params("name", name),
        (ResultSet rs, int rowNum) -> toValidationStampFilter(rs, pid -> null, bid -> null)
    );
  }
  // OK
  return o;
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

@Override
public Branch connectTemplateInstance(ID branchId, BranchTemplateInstanceConnectRequest request) {
  // Gets the branch
  Branch branch = structureService.getBranch(branchId);
  // Checks it is not connected yet
  if (branch.getType() != BranchType.CLASSIC) {
    throw new BranchCannotConnectToTemplateException(branch.getName());
  }
  // Checks the rights
  securityService.checkProjectFunction(branch, BranchTemplateMgt.class);
  // Gets the template definition
  ID templateId = ID.of(request.getTemplateId());
  TemplateDefinition templateDefinition = getTemplateDefinition(templateId)
      .orElseThrow(() -> new BranchNotTemplateDefinitionException(templateId));
  // Loads the branch template
  Branch template = structureService.getBranch(templateId);
  // Update request
  BranchTemplateInstanceSingleRequest instanceSingleRequest = new BranchTemplateInstanceSingleRequest(
      branch.getName(),
      request.isManual(),
      request.getParameters()
  );
  // Updates the instance
  updateTemplateInstance(branch.getName(), branch, template, instanceSingleRequest, templateDefinition);
  // OK
  return structureService.getBranch(branchId);
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

@Override
public Branch cloneBranch(Branch sourceBranch, BranchCloneRequest request) {
  // Replacement function
  Function<String, String> replacementFn = replacementFn(request.getReplacements());
  // Description of the target branch
  String targetDescription = replacementFn.apply(sourceBranch.getDescription());
  // Creates the branch
  Branch targetBranch = structureService.newBranch(
      Branch.of(
          sourceBranch.getProject(),
          NameDescription.nd(request.getName(), targetDescription)
      )
  );
  // Copies the configuration
  doCopy(sourceBranch, targetBranch, replacementFn, SyncPolicy.COPY);
  // OK
  return targetBranch;
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

protected Branch createBranchForTemplateInstance(Branch templateBranch, String branchName) {
  return structureService.newBranch(
      Branch.of(
          templateBranch.getProject(),
          NameDescription.nd(
              NameDescription.escapeName(branchName),
              ""
          )
      )
  );
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-service

@Override
public Project cloneProject(Project sourceProject, ProjectCloneRequest request) {
  // Replacement function
  Function<String, String> replacementFn = replacementFn(request.getReplacements());
  // Description of the target project
  String targetProjectDescription = replacementFn.apply(sourceProject.getDescription());
  // Creates the project
  Project targetProject = structureService.newProject(
      Project.of(
          NameDescription.nd(request.getName(), targetProjectDescription)
      )
  );
  // Copies the properties for the project
  doCopyProperties(sourceProject, targetProject, replacementFn, SyncPolicy.COPY);
  // Creates a copy of the branch
  Branch sourceBranch = structureService.getBranch(request.getSourceBranchId());
  String targetBranchName = replacementFn.apply(sourceBranch.getName());
  String targetBranchDescription = replacementFn.apply(sourceBranch.getDescription());
  Branch targetBranch = structureService.newBranch(
      Branch.of(
          targetProject,
          NameDescription.nd(targetBranchName, targetBranchDescription)
      )
  );
  // Configuration of the new branch
  doCopy(sourceBranch, targetBranch, replacementFn, SyncPolicy.COPY);
  // OK
  return targetProject;
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-repository-impl

protected Branch toBranch(ResultSet rs, Function<ID, Project> projectSupplier) throws SQLException {
  ID projectId = id(rs, "projectId");
  ID branchId = id(rs);
  return Branch.of(
      projectSupplier.apply(projectId),
      new NameDescription(
          rs.getString("name"),
          rs.getString("description")
      )
  )
      .withId(branchId)
      .withSignature(readSignature(rs))
      .withType(getBranchType(branchId))
      .withDisabled(rs.getBoolean("disabled"));
}

相关文章