Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void conversion_config_to_string() throws ConversionException {
//Arrange
Function<Configuration, String> conv = new JsonConverters().configToString();
Configuration testConfig = new Configuration(configName, configDescription);
String expected = "{\"name\":\"" + configName + "\",\"description\":\"" + configDescription + "\",\"isProtected\":false,\"isDynamic\":false,\"configuresBlockGWAndArchiver\":false,\"iocs\":[],\"blocks\":[],\"groups\":[],\"components\":[],\"history\":[]}";
String expected = "{\"name\":\"" + configName + "\",\"description\":\"" + configDescription + "\",\"isProtected\":false,\"isDynamic\":false,\"configuresBlockGWAndArchiver\":false,\"iocs\":[],\"blocks\":[],\"groups\":[],\"components\":[],\"history\":[],\"globalmacros\":[]}";

//Act
String test = conv.apply(testConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class Configuration extends ModelObject {
private List<Group> groups = new ArrayList<>();
private List<ComponentInfo> components = new ArrayList<>();
private List<String> history = new ArrayList<>();
private List<GlobalMacro> globalmacros = new ArrayList<>();

/**
* Create a new configuration.
Expand Down Expand Up @@ -81,11 +82,12 @@ public Configuration(String name, String description) {
* automatically
* @param configuresBlockGWAndArchiver True this configuration includes the block gateway and archive files;
* False these are generated by the block server
* @param globalmacros The global macros
*/
public Configuration(String name, String description, String defaultSynoptic, Collection<Ioc> iocs,
Collection<Block> blocks, Collection<Group> groups, Collection<ComponentInfo> components,
Collection<String> history, boolean isProtected, boolean isDynamic,
boolean configuresBlockGWAndArchiver) {
boolean configuresBlockGWAndArchiver, Collection<GlobalMacro> globalmacros) {
this.name = name;
this.description = description;
this.synoptic = defaultSynoptic == null || defaultSynoptic.equals("") ? ConfigEditing.NONE_SYNOPTIC_NAME
Expand Down Expand Up @@ -114,6 +116,39 @@ public Configuration(String name, String description, String defaultSynoptic, Co
for (String date : history) {
this.history.add(date);
}

if (null != globalmacros) {
for (GlobalMacro globalMacro : globalmacros) {
this.globalmacros.add(new GlobalMacro(globalMacro));
}
}
}

/**
* Create a new configuration.
*
* @param name The configuration name
* @param description The configuration description
* @param defaultSynoptic The default synoptic to open when the configuration is
* current
* @param iocs The IOCs associated with the configuration
* @param blocks The configuration's blocks
* @param groups The configuration's groups
* @param components The configuration's components
* @param history A collection of dates when the configuration was
* updated
* @param isProtected Config is protected and can only be modified or
* deleted in manager mode
* @param isDynamic Config is marked as dynamic and can be changed
* automatically
* @param configuresBlockGWAndArchiver True this configuration includes the block gateway and archive files;
* False these are generated by the block server
*/
public Configuration(String name, String description, String defaultSynoptic, Collection<Ioc> iocs,
Collection<Block> blocks, Collection<Group> groups, Collection<ComponentInfo> components,
Collection<String> history, boolean isProtected, boolean isDynamic, boolean configuresBlockGWAndArchiver) {
this(name, description, defaultSynoptic, iocs, blocks, groups, components, history, isProtected, isDynamic,
configuresBlockGWAndArchiver, null);
}

/**
Expand All @@ -123,7 +158,8 @@ public Configuration(String name, String description, String defaultSynoptic, Co
*/
public Configuration(Configuration other) {
this(other.name(), other.description(), other.synoptic(), other.getIocs(), other.getBlocks(), other.getGroups(),
other.getComponents(), other.getHistory(), other.isProtected, other.isDynamic, other.configuresBlockGWAndArchiver);
other.getComponents(), other.getHistory(), other.isProtected, other.isDynamic,
other.configuresBlockGWAndArchiver, other.getGlobalmacros());
this.pv = other.pv;
}

Expand Down Expand Up @@ -251,4 +287,11 @@ public String toString() {
public String getName() {
return name;
}

/**
* @return A collection of the configuration's blocks
*/
public List<GlobalMacro> getGlobalmacros() {
return globalmacros != null ? new ArrayList<>(globalmacros) : Collections.<GlobalMacro>emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* This file is part of the ISIS IBEX application.
* Copyright (C) 2012-2025 Science & Technology Facilities Council.
* All rights reserved.
*
* This program is distributed in the hope that it will be useful.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution.
* EXCEPT AS EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM
* AND ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more details.
*
* You should have received a copy of the Eclipse Public License v1.0
* along with this program; if not, you can obtain a copy from
* https://www.eclipse.org/org/documents/epl-v10.php or
* http://opensource.org/licenses/eclipse-1.0.php
*/

package uk.ac.stfc.isis.ibex.configserver.configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import uk.ac.stfc.isis.ibex.model.ModelObject;

/**
* Represents a global macro.
*
* Contains the IOC name, or none, and a list of associated macros
*
*/
public class GlobalMacro extends ModelObject implements Comparable<GlobalMacro> {

private final String name;

private Map<String, String> macros;

/**
* Create a Global Macro with a given name.
*
* @param name The IOC name (or global)
*/
public GlobalMacro(String name) {
this.name = name;
}

/**
* Create a copy of a Global Macro list for an IOC (or global).
*
* @param globalMacro The Global Macro to copy
*/
public GlobalMacro(GlobalMacro globalMacro) {
this.name = globalMacro.getName();
//this.macros = new ArrayList<>(globalMacro.getMacros());
this.macros = new HashMap<String, String>(globalMacro.getMacros());
}

/**
* @return The IOC name
*/
public String getName() {
return name;
}

/**
* @return A collection of macros
*/
public Map<String, String> getMacros() {
return Optional.ofNullable(macros).orElseGet(HashMap::new);
}

/**
* Compares this GlobalMacro to another based on name. Used for sorting.
*/
@Override
public int compareTo(GlobalMacro other) {
if (this.name != null && other.name != null) {
return this.name.compareTo(other.name);
}
return 0;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
GlobalMacro other = (GlobalMacro) obj;
if (this.name == null && other.name == null) {
return true;
}
if (this.name == null || other.name == null) {
return false;
}
return this.name.equals(other.name);
}

@Override
public int hashCode() {
return name == null ? 0 : name.hashCode();
}

@Override
public String toString() {
return "GlobalMacro [name=" + name + ", macros=" + macros + "]";
}
}
Loading
Loading