-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
222 additions
and
118 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
src/main/java/io/jenkins/plugins/monitoring/MonitorUserProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.jenkins.plugins.monitoring; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.model.User; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
/** | ||
* A {@link hudson.model.UserProperty} to store the json configuration per user as property. | ||
*/ | ||
public class MonitorUserProperty extends hudson.model.UserProperty { | ||
|
||
private Collection<MonitorProperty> properties; | ||
|
||
public MonitorUserProperty() { | ||
|
||
} | ||
|
||
public MonitorUserProperty(MonitorProperty defaultProp) { | ||
this.properties = new ArrayList<>(); | ||
this.properties.add(defaultProp); | ||
} | ||
|
||
public Collection<MonitorProperty> getProperties() { | ||
return properties; | ||
} | ||
|
||
public MonitorProperty getView(String id) { | ||
return this.getProperties().stream() | ||
.filter(monitorProperty -> monitorProperty.getId().equals(id)) | ||
.findFirst().orElse(null); | ||
} | ||
|
||
public void setProperties(Collection<MonitorProperty> properties) { | ||
this.properties = properties; | ||
} | ||
|
||
public void createOrUpdate(String id, String config) { | ||
MonitorProperty property = this.getProperties().stream() | ||
.filter(monitorProperty -> monitorProperty.getId().equals(id)) | ||
.findFirst().orElse(null); | ||
|
||
if (property == null) { | ||
this.getProperties().add(new MonitorProperty(id, config)); | ||
} else { | ||
property.setConfig(config); | ||
} | ||
} | ||
|
||
public static class MonitorProperty { | ||
|
||
private final String id; | ||
private String config; | ||
|
||
public MonitorProperty(String id, String config) { | ||
this.id = id; | ||
this.config = config; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getConfig() { | ||
return config; | ||
} | ||
|
||
public void setConfig(String config) { | ||
this.config = config; | ||
} | ||
|
||
} | ||
|
||
@Extension | ||
public static class MonitorPropertyDescriptor extends UserPropertyDescriptor { | ||
|
||
@Override | ||
public UserProperty newInstance(User user) { | ||
return new MonitorUserProperty(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return "Monitoring Configuration"; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/resources/io/jenkins/plugins/monitoring/MonitorUserProperty/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?jelly escape-by-default='true'?> | ||
|
||
<j:jelly xmlns:j="jelly:core"> | ||
|
||
<p>Nothing to configure here!</p> | ||
|
||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.