Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void GIVEN_blank_default_synoptic_WHEN_creating_configuration_THEN_defaul
String defaultSynoptic = "";

// Act
Configuration config = new Configuration("name", "description", defaultSynoptic, iocs, blocks, groups, components, history, true, false, false);
Configuration config = new Configuration("name", "description", defaultSynoptic, iocs, blocks, groups, components, history, true, false, false, null);

// Assert
assertEquals(ConfigEditing.NONE_SYNOPTIC_NAME, config.synoptic());
Expand All @@ -58,7 +58,7 @@ public void GIVEN_blank_default_synoptic_WHEN_creating_configuration_THEN_defaul

@Test
public void GIVEN_non_dynamic_configuration_THEN_display_name_is_the_same_as_config_name() {
Configuration config = new Configuration("name", "description", "", iocs, blocks, groups, components, history, false, false, false);
Configuration config = new Configuration("name", "description", "", iocs, blocks, groups, components, history, false, false, false, null);

// Assert
assertEquals(config.getDisplayName(), "name");
Expand All @@ -67,7 +67,7 @@ public void GIVEN_non_dynamic_configuration_THEN_display_name_is_the_same_as_con

@Test
public void GIVEN_dynamic_configuration_THEN_display_name_has_dynamic_appended() {
Configuration config = new Configuration("name", "description", "", iocs, blocks, groups, components, history, false, true, false);
Configuration config = new Configuration("name", "description", "", iocs, blocks, groups, components, history, false, true, false, null);

// Assert
assertEquals(config.getDisplayName(), "name (dynamic)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public static Configuration emptyConfig() {
Collections.<String>emptyList(),
true,
false,
false);
false,
null);
}

protected void populateConfig() {
Expand All @@ -146,7 +147,7 @@ protected void populateConfig() {
}

protected Configuration config() {
return new Configuration(NAME, DESCRIPTION, SYNOPTIC, iocs, blocks, groups, components, history, true, false, false);
return new Configuration(NAME, DESCRIPTION, SYNOPTIC, iocs, blocks, groups, components, history, true, false, false, null);
}

protected EditableConfiguration edit(Configuration config) {
Expand Down Expand Up @@ -217,9 +218,9 @@ public void GIVEN_configuration_WHEN_component_added_THEN_blocks_from_component_

var component = new Configuration("comp", "desc", "", Collections.emptyList(),
List.of(new Block("comp_blockname", "", false, false)),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, true, false);
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, true, false, null);

var config = new Configuration("name", "description", "", iocs, blocks, groups, components, history, false, true, false);
var config = new Configuration("name", "description", "", iocs, blocks, groups, components, history, false, true, false, null);
var editable = new EditableConfiguration(config, Collections.emptyList(), List.of(component), Collections.emptyList());

assertEquals(editable.getAllBlocks().size(), 0);
Expand All @@ -238,7 +239,7 @@ public void GIVEN_configuration_WHEN_component_added_THEN_blocks_from_component_
public void GIVEN_component_with_group_WHEN_component_added_THEN_group_from_component_read_only() {
var group = new Group("comp_group", Collections.emptyList(), "comp");
var component = new Configuration("comp", "desc", "", Collections.emptyList(), Collections.emptyList(),
List.of(group), Collections.emptyList(), Collections.emptyList(), false, true, false);
List.of(group), Collections.emptyList(), Collections.emptyList(), false, true, false, null);
var editable = new EditableConfiguration(emptyConfig(), Collections.emptyList(), List.of(component), Collections.emptyList());

assertEquals(editable.getEditableGroups().size(), 0);
Expand All @@ -261,7 +262,7 @@ public void GIVEN_component_with_group_WHEN_component_added_THEN_group_from_comp
public void GIVEN_component_with_block_not_in_group_WHEN_component_added_THEN_block_from_component() {
var block = new Block("block", "PV", true, true);
var component = new Configuration("comp", "desc", "", Collections.emptyList(), List.of(block), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(), false, true, false);
Collections.emptyList(), Collections.emptyList(), false, true, false, null);
var editable = new EditableConfiguration(emptyConfig(), Collections.emptyList(), List.of(component), Collections.emptyList());

assertEquals(editable.getBlocksOutsideGroup().size(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public static void setUp() {
editableIocs.add(editableIoc);

source = new Configuration(COMPONENT_NAME, COMPONENT_DESC, null, Arrays.asList(new Ioc(editableIoc)), Arrays.asList(BLOCK),
Arrays.asList(GROUP), Collections.emptyList(), Collections.emptyList(), false, false, false);
Arrays.asList(GROUP), Collections.emptyList(), Collections.emptyList(), false, false, false, null);
empty = new Configuration("EMPTY", "EMTPY DESC", null, Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, false, false);
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), false, false, false, null);
destination = new EditableConfiguration(empty, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());

ImportConverter.convert(source, destination, SOURCE_PREFIX, DESTINATION_PREFIX, editableIocs);
Expand Down
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,12 @@ 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));
}
}
}

/**
Expand All @@ -123,7 +131,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 +260,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