Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Component Property API #2717

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions src/main/java/org/dependencytrack/model/ComponentProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* This file is part of Dependency-Track.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) Steve Springett. All Rights Reserved.
*/
package org.dependencytrack.model;

import alpine.model.IConfigProperty;
import alpine.server.json.TrimmedStringDeserializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import javax.jdo.annotations.Column;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
* User-defined key/value model for individual components.
*
* @author Steve Springett
* @since 4.9.0
*/
@PersistenceCapable(table = "COMPONENT_PROPERTY")
@Unique(name="COMPONENT_PROPERTY_KEYS_IDX", members={"component", "groupName", "propertyName"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ComponentProperty implements IConfigProperty, Serializable {

private static final long serialVersionUID = -6728711858486727102L;

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.NATIVE)
@JsonIgnore
private long id;

@Persistent
@Column(name = "COMPONENT_ID", allowsNull = "false")
private Component component;

@Persistent
@Column(name = "GROUPNAME", allowsNull = "false")
@NotBlank
@Size(min = 1, max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = "[\\P{Cc}]+", message = "The groupName must not contain control characters")
private String groupName;

@Persistent
@Column(name = "PROPERTYNAME", allowsNull = "false")
@NotBlank
@Size(min = 1, max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = "[\\P{Cc}]+", message = "The propertyName must not contain control characters")
private String propertyName;

@Persistent
@Column(name = "PROPERTYVALUE", length = 1024)
@Size(min = 0, max = 1024)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = "[\\P{Cc}]+", message = "The propertyValue must not contain control characters")
private String propertyValue;

@Persistent
@Column(name = "PROPERTYTYPE", jdbcType = "VARCHAR", allowsNull = "false")
@NotNull
private PropertyType propertyType;

@Persistent
@Column(name = "DESCRIPTION")
@Size(max = 255)
@JsonDeserialize(using = TrimmedStringDeserializer.class)
@Pattern(regexp = "[\\P{Cc}]+", message = "The description must not contain control characters")
private String description;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public Component getComponent() {
return component;
}

public void setComponent(Component component) {
this.component = component;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}

public String getPropertyName() {
return propertyName;
}

public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}

public String getPropertyValue() {
return propertyValue;
}

public void setPropertyValue(String propertyValue) {
this.propertyValue = propertyValue;
}

public PropertyType getPropertyType() {
return propertyType;
}

public void setPropertyType(PropertyType propertyType) {
this.propertyType = propertyType;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}
Loading
Loading