<commit_before>/**
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * 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 org.jboss.pnc.rest.restmodel;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.jboss.pnc.model.BuildRecord;
import org.jboss.pnc.rest.validation.groups.WhenCreatingNew;
import org.jboss.pnc.rest.validation.groups.WhenUpdating;
import org.jboss.pnc.spi.BuildCoordinationStatus;
import org.jboss.pnc.spi.executor.BuildExecutionConfiguration;
import org.jboss.pnc.spi.executor.BuildExecutionSession;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import static org.jboss.pnc.rest.utils.Utility.performIfNotNull;

@XmlRootElement(name = "BuildRecord")
public class BuildRecordRest implements GenericRestEntity<Integer> {

    @NotNull(groups = WhenUpdating.class)
    @Null(groups = WhenCreatingNew.class)
    private Integer id;

    private Date submitTime;

    private Date startTime;

    private Date endTime;

    @ApiModelProperty(dataType = "string")
    private BuildCoordinationStatus status;

    private Integer buildConfigurationId;

    private String buildConfigurationName;

    private Integer buildConfigurationRev;

    private Integer userId;

    private String username;

    private String scmRepoURL;

    private String scmRevision;

    private Integer buildEnvironmentId;

    private Map<String, String> attributes = new HashMap<>();

    private String liveLogsUri;

    private Integer buildConfigSetRecordId;

    private String buildContentId;

    /**
     * The IDs of the build record sets which represent the builds performed for a milestone to which this build record belongs
     */
    private Integer productMilestoneId;

    /**
     * Required in order to use rsql on user
     */
    private UserRest user;

    /**
     * Required in order to use rsql on buildConfiguration
     */
    private BuildConfigurationAuditedRest buildConfigurationAudited;

    @Getter
    @Setter
    private String executionRootName;

    @Getter
    @Setter
    private String executionRootVersion;


    public BuildRecordRest() {
    }

    public BuildRecordRest(BuildRecord buildRecord) {
        this.id = buildRecord.getId();
        this.submitTime = buildRecord.getSubmitTime();
        this.startTime = buildRecord.getStartTime();
        this.endTime = buildRecord.getEndTime();
        this.scmRepoURL = buildRecord.getScmRepoURL();
        this.scmRevision = buildRecord.getScmRevision();
        this.attributes = buildRecord.getAttributes();
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationId = buildRecord.getBuildConfigurationAudited().getId().getId());
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationName = buildRecord.getBuildConfigurationAudited().getName());
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationRev = buildRecord.getBuildConfigurationAudited().getRev());
        performIfNotNull(buildRecord.getUser(), () -> userId = buildRecord.getUser().getId());
        performIfNotNull(buildRecord.getUser(), () -> username = buildRecord.getUser().getUsername());
        performIfNotNull(buildRecord.getBuildEnvironment(), () -> buildEnvironmentId = buildRecord.getBuildEnvironment().getId());
        this.status = BuildCoordinationStatus.fromBuildStatus(buildRecord.getStatus());
        if (buildRecord.getBuildConfigSetRecord() != null)
            this.buildConfigSetRecordId = buildRecord.getBuildConfigSetRecord().getId();

        this.buildContentId = buildRecord.getBuildContentId();
        
        performIfNotNull(buildRecord.getProductMilestone(), () -> productMilestoneId = buildRecord.getProductMilestone().getId());
        performIfNotNull(buildRecord.getUser(), () -> user = new UserRest(buildRecord.getUser()));
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationAudited = new BuildConfigurationAuditedRest(
                        buildRecord.getBuildConfigurationAudited()));

        executionRootName = buildRecord.getExecutionRootName();
        executionRootVersion = buildRecord.getExecutionRootVersion();
    }

    public BuildRecordRest(BuildExecutionSession buildExecutionSession, Date submitTime, UserRest user,
            BuildConfigurationAuditedRest buildConfigurationAudited) {
        this.id = buildExecutionSession.getId();
        this.submitTime = submitTime;
        this.startTime = buildExecutionSession.getStartTime();
        this.endTime = buildExecutionSession.getEndTime();
        BuildExecutionConfiguration buildExecutionConfig = buildExecutionSession.getBuildExecutionConfiguration();

        //TODO Why masking i.e. BUILD_WAITING status with BUILDING ?
        this.status = BuildCoordinationStatus.fromBuildExecutionStatus(buildExecutionSession.getStatus());
        buildExecutionSession.getLiveLogsUri().ifPresent(logsUri -> setLiveLogsUri(logsUri.toString()));

        this.userId = user.getId();
        this.username = user.getUsername();

        this.user = user;
        this.buildConfigurationAudited = buildConfigurationAudited;

        this.buildContentId = buildExecutionConfig.getBuildContentId();

        this.buildConfigurationName = buildExecutionConfig.getName();
        this.scmRepoURL = buildExecutionConfig.getScmRepoURL();
        this.scmRevision = buildExecutionConfig.getScmRevision();
    }

    public BuildRecordRest(Integer id, BuildCoordinationStatus buildCoordinationStatus, Date submitTime, Date startTime,
            Date endTime, UserRest user, BuildConfigurationAuditedRest buildConfigurationAudited) {
        this.id = id;
        this.submitTime = submitTime;
        this.startTime = startTime;
        this.endTime = endTime;

        this.status = buildCoordinationStatus;

        this.userId = user.getId();
        this.username = user.getUsername();

        this.user = user;
        this.buildConfigurationAudited = buildConfigurationAudited;
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public Date getSubmitTime() {
        return submitTime;
    }

    public void setSubmitTime(Date submitTime) {
        this.submitTime = submitTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }<commit_msg>Add missing build configuration name to the list of builds.<commit_after>/**
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * 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 org.jboss.pnc.rest.restmodel;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.jboss.pnc.model.BuildRecord;
import org.jboss.pnc.rest.validation.groups.WhenCreatingNew;
import org.jboss.pnc.rest.validation.groups.WhenUpdating;
import org.jboss.pnc.spi.BuildCoordinationStatus;
import org.jboss.pnc.spi.executor.BuildExecutionConfiguration;
import org.jboss.pnc.spi.executor.BuildExecutionSession;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import static org.jboss.pnc.rest.utils.Utility.performIfNotNull;

@XmlRootElement(name = "BuildRecord")
public class BuildRecordRest implements GenericRestEntity<Integer> {

    @NotNull(groups = WhenUpdating.class)
    @Null(groups = WhenCreatingNew.class)
    private Integer id;

    private Date submitTime;

    private Date startTime;

    private Date endTime;

    @ApiModelProperty(dataType = "string")
    private BuildCoordinationStatus status;

    private Integer buildConfigurationId;

    private String buildConfigurationName;

    private Integer buildConfigurationRev;

    private Integer userId;

    private String username;

    private String scmRepoURL;

    private String scmRevision;

    private Integer buildEnvironmentId;

    private Map<String, String> attributes = new HashMap<>();

    private String liveLogsUri;

    private Integer buildConfigSetRecordId;

    private String buildContentId;

    /**
     * The IDs of the build record sets which represent the builds performed for a milestone to which this build record belongs
     */
    private Integer productMilestoneId;

    /**
     * Required in order to use rsql on user
     */
    private UserRest user;

    /**
     * Required in order to use rsql on buildConfiguration
     */
    private BuildConfigurationAuditedRest buildConfigurationAudited;

    @Getter
    @Setter
    private String executionRootName;

    @Getter
    @Setter
    private String executionRootVersion;


    public BuildRecordRest() {
    }

    public BuildRecordRest(BuildRecord buildRecord) {
        this.id = buildRecord.getId();
        this.submitTime = buildRecord.getSubmitTime();
        this.startTime = buildRecord.getStartTime();
        this.endTime = buildRecord.getEndTime();
        this.scmRepoURL = buildRecord.getScmRepoURL();
        this.scmRevision = buildRecord.getScmRevision();
        this.attributes = buildRecord.getAttributes();
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationId = buildRecord.getBuildConfigurationAudited().getId().getId());
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationName = buildRecord.getBuildConfigurationAudited().getName());
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationRev = buildRecord.getBuildConfigurationAudited().getRev());
        performIfNotNull(buildRecord.getUser(), () -> userId = buildRecord.getUser().getId());
        performIfNotNull(buildRecord.getUser(), () -> username = buildRecord.getUser().getUsername());
        performIfNotNull(buildRecord.getBuildEnvironment(), () -> buildEnvironmentId = buildRecord.getBuildEnvironment().getId());
        this.status = BuildCoordinationStatus.fromBuildStatus(buildRecord.getStatus());
        if (buildRecord.getBuildConfigSetRecord() != null)
            this.buildConfigSetRecordId = buildRecord.getBuildConfigSetRecord().getId();

        this.buildContentId = buildRecord.getBuildContentId();
        
        performIfNotNull(buildRecord.getProductMilestone(), () -> productMilestoneId = buildRecord.getProductMilestone().getId());
        performIfNotNull(buildRecord.getUser(), () -> user = new UserRest(buildRecord.getUser()));
        performIfNotNull(buildRecord.getBuildConfigurationAudited(),
                () -> buildConfigurationAudited = new BuildConfigurationAuditedRest(
                        buildRecord.getBuildConfigurationAudited()));

        executionRootName = buildRecord.getExecutionRootName();
        executionRootVersion = buildRecord.getExecutionRootVersion();
    }

    public BuildRecordRest(BuildExecutionSession buildExecutionSession, Date submitTime, UserRest user,
            BuildConfigurationAuditedRest buildConfigurationAudited) {
        this.id = buildExecutionSession.getId();
        this.submitTime = submitTime;
        this.startTime = buildExecutionSession.getStartTime();
        this.endTime = buildExecutionSession.getEndTime();
        BuildExecutionConfiguration buildExecutionConfig = buildExecutionSession.getBuildExecutionConfiguration();

        //TODO Why masking i.e. BUILD_WAITING status with BUILDING ?
        this.status = BuildCoordinationStatus.fromBuildExecutionStatus(buildExecutionSession.getStatus());
        buildExecutionSession.getLiveLogsUri().ifPresent(logsUri -> setLiveLogsUri(logsUri.toString()));

        this.userId = user.getId();
        this.username = user.getUsername();

        this.user = user;
        this.buildConfigurationAudited = buildConfigurationAudited;

        this.buildContentId = buildExecutionConfig.getBuildContentId();

        this.buildConfigurationName = buildExecutionConfig.getName();
        this.scmRepoURL = buildExecutionConfig.getScmRepoURL();
        this.scmRevision = buildExecutionConfig.getScmRevision();
    }

    public BuildRecordRest(Integer id, BuildCoordinationStatus buildCoordinationStatus, Date submitTime, Date startTime,
            Date endTime, UserRest user, BuildConfigurationAuditedRest buildConfigurationAudited) {
        this.id = id;
        this.submitTime = submitTime;
        this.startTime = startTime;
        this.endTime = endTime;

        this.status = buildCoordinationStatus;

        this.userId = user.getId();
        this.username = user.getUsername();

        this.user = user;
        this.buildConfigurationAudited = buildConfigurationAudited;
        this.buildConfigurationName = buildConfigurationAudited.getName();
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public Date getSubmitTime() {
        return submitTime;
    }

    public void setSubmitTime(Date submitTime) {
        this.submitTime = submitTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
{'fraction_non_alphanumeric': 0.08760352838192714, 'fraction_numerical': 0.0010773685273718942, 'mean_word_length': 3.5952970297029703, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1375428', 'n_tokens_mistral': 3823, 'n_tokens_neox': 3721, 'n_words': 881}