org.zodiac.actuate.application.maintenance.AppMaintenanceOperatorRegistry Maven / Gradle / Ivy
package org.zodiac.actuate.application.maintenance;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.RequestMethod;
import org.zodiac.commons.util.Colls;
public class AppMaintenanceOperatorRegistry {
/*操作名称与与操作对应关系。*/
private Map maintenanceOperatorsMap;
public AppMaintenanceOperatorRegistry(List maintenanceOperators) {
if (Colls.emptyColl(maintenanceOperators)) {
maintenanceOperatorsMap = Collections.emptyMap();
return;
}
maintenanceOperatorsMap = maintenanceOperators.stream().collect(Collectors.toMap(AppMaintenanceOperator::getOperatorName, op -> op));
}
public Optional getOperator(String name) {
return getOperator(name, null);
}
public Optional getOperator(String name, RequestMethod method) {
AppMaintenanceOperator operator = maintenanceOperatorsMap.get(name);
if (null == operator) {
/*对应名称的操作不存在*/
return Optional.empty();
}
if (null == method) {
/*不指定方法,认为是没有限制*/
return Optional.of(operator);
}
if (null != method) {
/*指定方法,认为是有限制*/
if (operator.supportedMethods().contains(method)) {
/*支持的方法*/
return Optional.of(operator);
}
}
return Optional.empty();
}
public Map getStatus() {
Map result = Colls.map();
if (!maintenanceOperatorsMap.isEmpty()) {
maintenanceOperatorsMap.values().forEach(it -> result.put(it.getOperatorName(), it.getStatus()));
}
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy