repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/HasPackageChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // }
import com.github.vbauer.jconditions.annotation.HasPackage; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class HasPackageChecker implements ConditionChecker<HasPackage> { /** * {@inheritDoc} */ @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/HasPackageChecker.java import com.github.vbauer.jconditions.annotation.HasPackage; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class HasPackageChecker implements ConditionChecker<HasPackage> { /** * {@inheritDoc} */ @Override
public boolean isSatisfied(final CheckerContext<HasPackage> context) {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/RunningOnOSChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // }
import com.github.vbauer.jconditions.annotation.RunningOnOS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class RunningOnOSChecker implements ConditionChecker<RunningOnOS> { private static final String PROPERTY_OS_NAME = "os.name"; /** * {@inheritDoc} */ @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/RunningOnOSChecker.java import com.github.vbauer.jconditions.annotation.RunningOnOS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class RunningOnOSChecker implements ConditionChecker<RunningOnOS> { private static final String PROPERTY_OS_NAME = "os.name"; /** * {@inheritDoc} */ @Override
public boolean isSatisfied(final CheckerContext<RunningOnOS> context) {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/RunningOnOSChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // }
import com.github.vbauer.jconditions.annotation.RunningOnOS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class RunningOnOSChecker implements ConditionChecker<RunningOnOS> { private static final String PROPERTY_OS_NAME = "os.name"; /** * {@inheritDoc} */ @Override public boolean isSatisfied(final CheckerContext<RunningOnOS> context) { final RunningOnOS annotation = context.getAnnotation(); final String[] operationSystems = annotation.value();
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/RunningOnOSChecker.java import com.github.vbauer.jconditions.annotation.RunningOnOS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class RunningOnOSChecker implements ConditionChecker<RunningOnOS> { private static final String PROPERTY_OS_NAME = "os.name"; /** * {@inheritDoc} */ @Override public boolean isSatisfied(final CheckerContext<RunningOnOS> context) { final RunningOnOS annotation = context.getAnnotation(); final String[] operationSystems = annotation.value();
return PropUtils.hasAnyWithProperties(currentOS(), operationSystems);
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/ExistsOnFSChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/FSUtils.java // public final class FSUtils { // // private FSUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean exists(final String path) { // final File file = new File(path); // return file.exists(); // } // // public static boolean fileExists(final String path) { // final File file = new File(path); // return file.exists() && file.isFile(); // } // // public static boolean directoryExists(final String path) { // final File file = new File(path); // return file.exists() && file.isDirectory(); // } // // public static boolean isSymlink(final String path) throws IOException { // final File file = new File(path); // final File fileInCanonicalDir; // // if (file.getParent() == null) { // fileInCanonicalDir = file; // } else { // fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); // } // // final File canonicalFile = fileInCanonicalDir.getCanonicalFile(); // final File absoluteFile = fileInCanonicalDir.getAbsoluteFile(); // return !canonicalFile.equals(absoluteFile); // } // // public static boolean deleteFile(final String path) { // final File file = new File(path); // return file.delete(); // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // }
import com.github.vbauer.jconditions.annotation.ExistsOnFS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.FSUtils; import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class ExistsOnFSChecker implements ConditionChecker<ExistsOnFS> { /** * {@inheritDoc} */ @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/FSUtils.java // public final class FSUtils { // // private FSUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean exists(final String path) { // final File file = new File(path); // return file.exists(); // } // // public static boolean fileExists(final String path) { // final File file = new File(path); // return file.exists() && file.isFile(); // } // // public static boolean directoryExists(final String path) { // final File file = new File(path); // return file.exists() && file.isDirectory(); // } // // public static boolean isSymlink(final String path) throws IOException { // final File file = new File(path); // final File fileInCanonicalDir; // // if (file.getParent() == null) { // fileInCanonicalDir = file; // } else { // fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); // } // // final File canonicalFile = fileInCanonicalDir.getCanonicalFile(); // final File absoluteFile = fileInCanonicalDir.getAbsoluteFile(); // return !canonicalFile.equals(absoluteFile); // } // // public static boolean deleteFile(final String path) { // final File file = new File(path); // return file.delete(); // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/ExistsOnFSChecker.java import com.github.vbauer.jconditions.annotation.ExistsOnFS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.FSUtils; import com.github.vbauer.jconditions.util.PropUtils; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class ExistsOnFSChecker implements ConditionChecker<ExistsOnFS> { /** * {@inheritDoc} */ @Override
public boolean isSatisfied(final CheckerContext<ExistsOnFS> context) throws Exception {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/ExistsOnFSChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/FSUtils.java // public final class FSUtils { // // private FSUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean exists(final String path) { // final File file = new File(path); // return file.exists(); // } // // public static boolean fileExists(final String path) { // final File file = new File(path); // return file.exists() && file.isFile(); // } // // public static boolean directoryExists(final String path) { // final File file = new File(path); // return file.exists() && file.isDirectory(); // } // // public static boolean isSymlink(final String path) throws IOException { // final File file = new File(path); // final File fileInCanonicalDir; // // if (file.getParent() == null) { // fileInCanonicalDir = file; // } else { // fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); // } // // final File canonicalFile = fileInCanonicalDir.getCanonicalFile(); // final File absoluteFile = fileInCanonicalDir.getAbsoluteFile(); // return !canonicalFile.equals(absoluteFile); // } // // public static boolean deleteFile(final String path) { // final File file = new File(path); // return file.delete(); // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // }
import com.github.vbauer.jconditions.annotation.ExistsOnFS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.FSUtils; import com.github.vbauer.jconditions.util.PropUtils;
return isSatisfied(filePaths, types); } private boolean isSatisfied( final String[] filePaths, final ExistsOnFS.Type... types ) throws Exception { for (final String filePath : filePaths) { if (isSatisfied(filePath, types)) { return false; } } return filePaths.length > 0; } private boolean isSatisfied( final String filePath, final ExistsOnFS.Type... types ) throws Exception { for (final ExistsOnFS.Type type : types) { if (!existsOnFS(filePath, type)) { return true; } } return false; } private boolean existsOnFS( final String filePath, final ExistsOnFS.Type type ) throws Exception {
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/FSUtils.java // public final class FSUtils { // // private FSUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean exists(final String path) { // final File file = new File(path); // return file.exists(); // } // // public static boolean fileExists(final String path) { // final File file = new File(path); // return file.exists() && file.isFile(); // } // // public static boolean directoryExists(final String path) { // final File file = new File(path); // return file.exists() && file.isDirectory(); // } // // public static boolean isSymlink(final String path) throws IOException { // final File file = new File(path); // final File fileInCanonicalDir; // // if (file.getParent() == null) { // fileInCanonicalDir = file; // } else { // fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); // } // // final File canonicalFile = fileInCanonicalDir.getCanonicalFile(); // final File absoluteFile = fileInCanonicalDir.getAbsoluteFile(); // return !canonicalFile.equals(absoluteFile); // } // // public static boolean deleteFile(final String path) { // final File file = new File(path); // return file.delete(); // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/ExistsOnFSChecker.java import com.github.vbauer.jconditions.annotation.ExistsOnFS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.FSUtils; import com.github.vbauer.jconditions.util.PropUtils; return isSatisfied(filePaths, types); } private boolean isSatisfied( final String[] filePaths, final ExistsOnFS.Type... types ) throws Exception { for (final String filePath : filePaths) { if (isSatisfied(filePath, types)) { return false; } } return filePaths.length > 0; } private boolean isSatisfied( final String filePath, final ExistsOnFS.Type... types ) throws Exception { for (final ExistsOnFS.Type type : types) { if (!existsOnFS(filePath, type)) { return true; } } return false; } private boolean existsOnFS( final String filePath, final ExistsOnFS.Type type ) throws Exception {
final String path = PropUtils.injectProperties(filePath);
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/ExistsOnFSChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/FSUtils.java // public final class FSUtils { // // private FSUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean exists(final String path) { // final File file = new File(path); // return file.exists(); // } // // public static boolean fileExists(final String path) { // final File file = new File(path); // return file.exists() && file.isFile(); // } // // public static boolean directoryExists(final String path) { // final File file = new File(path); // return file.exists() && file.isDirectory(); // } // // public static boolean isSymlink(final String path) throws IOException { // final File file = new File(path); // final File fileInCanonicalDir; // // if (file.getParent() == null) { // fileInCanonicalDir = file; // } else { // fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); // } // // final File canonicalFile = fileInCanonicalDir.getCanonicalFile(); // final File absoluteFile = fileInCanonicalDir.getAbsoluteFile(); // return !canonicalFile.equals(absoluteFile); // } // // public static boolean deleteFile(final String path) { // final File file = new File(path); // return file.delete(); // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // }
import com.github.vbauer.jconditions.annotation.ExistsOnFS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.FSUtils; import com.github.vbauer.jconditions.util.PropUtils;
private boolean isSatisfied( final String[] filePaths, final ExistsOnFS.Type... types ) throws Exception { for (final String filePath : filePaths) { if (isSatisfied(filePath, types)) { return false; } } return filePaths.length > 0; } private boolean isSatisfied( final String filePath, final ExistsOnFS.Type... types ) throws Exception { for (final ExistsOnFS.Type type : types) { if (!existsOnFS(filePath, type)) { return true; } } return false; } private boolean existsOnFS( final String filePath, final ExistsOnFS.Type type ) throws Exception { final String path = PropUtils.injectProperties(filePath); switch (type) { case FILE:
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/FSUtils.java // public final class FSUtils { // // private FSUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean exists(final String path) { // final File file = new File(path); // return file.exists(); // } // // public static boolean fileExists(final String path) { // final File file = new File(path); // return file.exists() && file.isFile(); // } // // public static boolean directoryExists(final String path) { // final File file = new File(path); // return file.exists() && file.isDirectory(); // } // // public static boolean isSymlink(final String path) throws IOException { // final File file = new File(path); // final File fileInCanonicalDir; // // if (file.getParent() == null) { // fileInCanonicalDir = file; // } else { // fileInCanonicalDir = new File(file.getParentFile().getCanonicalFile(), file.getName()); // } // // final File canonicalFile = fileInCanonicalDir.getCanonicalFile(); // final File absoluteFile = fileInCanonicalDir.getAbsoluteFile(); // return !canonicalFile.equals(absoluteFile); // } // // public static boolean deleteFile(final String path) { // final File file = new File(path); // return file.delete(); // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/ExistsOnFSChecker.java import com.github.vbauer.jconditions.annotation.ExistsOnFS; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.FSUtils; import com.github.vbauer.jconditions.util.PropUtils; private boolean isSatisfied( final String[] filePaths, final ExistsOnFS.Type... types ) throws Exception { for (final String filePath : filePaths) { if (isSatisfied(filePath, types)) { return false; } } return filePaths.length > 0; } private boolean isSatisfied( final String filePath, final ExistsOnFS.Type... types ) throws Exception { for (final ExistsOnFS.Type type : types) { if (!existsOnFS(filePath, type)) { return true; } } return false; } private boolean existsOnFS( final String filePath, final ExistsOnFS.Type type ) throws Exception { final String path = PropUtils.injectProperties(filePath); switch (type) { case FILE:
return FSUtils.fileExists(path);
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/HasClassChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // }
import com.github.vbauer.jconditions.annotation.HasClass; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class HasClassChecker implements ConditionChecker<HasClass> { /** * {@inheritDoc} */ @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/HasClassChecker.java import com.github.vbauer.jconditions.annotation.HasClass; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class HasClassChecker implements ConditionChecker<HasClass> { /** * {@inheritDoc} */ @Override
public boolean isSatisfied(final CheckerContext<HasClass> context) {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/PropertyIsDefinedChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/TextUtils.java // public final class TextUtils { // // private TextUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean equalsSafe(final String a, final String b) { // return a == null && b == null || a != null && a.equals(b); // } // // public static boolean containsIgnoreCase(final String a, final String b) { // return a != null && b != null && a.toLowerCase().contains(b.toLowerCase()); // } // // }
import com.github.vbauer.jconditions.annotation.PropertyIsDefined; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; import com.github.vbauer.jconditions.util.TextUtils;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class PropertyIsDefinedChecker implements ConditionChecker<PropertyIsDefined> { /** * {@inheritDoc} */ @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/TextUtils.java // public final class TextUtils { // // private TextUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean equalsSafe(final String a, final String b) { // return a == null && b == null || a != null && a.equals(b); // } // // public static boolean containsIgnoreCase(final String a, final String b) { // return a != null && b != null && a.toLowerCase().contains(b.toLowerCase()); // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/PropertyIsDefinedChecker.java import com.github.vbauer.jconditions.annotation.PropertyIsDefined; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; import com.github.vbauer.jconditions.util.TextUtils; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class PropertyIsDefinedChecker implements ConditionChecker<PropertyIsDefined> { /** * {@inheritDoc} */ @Override
public boolean isSatisfied(final CheckerContext<PropertyIsDefined> context) {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/PropertyIsDefinedChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/TextUtils.java // public final class TextUtils { // // private TextUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean equalsSafe(final String a, final String b) { // return a == null && b == null || a != null && a.equals(b); // } // // public static boolean containsIgnoreCase(final String a, final String b) { // return a != null && b != null && a.toLowerCase().contains(b.toLowerCase()); // } // // }
import com.github.vbauer.jconditions.annotation.PropertyIsDefined; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; import com.github.vbauer.jconditions.util.TextUtils;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class PropertyIsDefinedChecker implements ConditionChecker<PropertyIsDefined> { /** * {@inheritDoc} */ @Override public boolean isSatisfied(final CheckerContext<PropertyIsDefined> context) { final PropertyIsDefined annotation = context.getAnnotation(); final String[] keys = annotation.keys(); final String[] values = annotation.values(); return isSatisfied(keys, values); } private boolean isSatisfied(final String[] keys, final String[] values) { int index = 0; for (final String key : keys) {
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/TextUtils.java // public final class TextUtils { // // private TextUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean equalsSafe(final String a, final String b) { // return a == null && b == null || a != null && a.equals(b); // } // // public static boolean containsIgnoreCase(final String a, final String b) { // return a != null && b != null && a.toLowerCase().contains(b.toLowerCase()); // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/PropertyIsDefinedChecker.java import com.github.vbauer.jconditions.annotation.PropertyIsDefined; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; import com.github.vbauer.jconditions.util.TextUtils; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class PropertyIsDefinedChecker implements ConditionChecker<PropertyIsDefined> { /** * {@inheritDoc} */ @Override public boolean isSatisfied(final CheckerContext<PropertyIsDefined> context) { final PropertyIsDefined annotation = context.getAnnotation(); final String[] keys = annotation.keys(); final String[] values = annotation.values(); return isSatisfied(keys, values); } private boolean isSatisfied(final String[] keys, final String[] values) { int index = 0; for (final String key : keys) {
final String variable = PropUtils.getSystemProperty(
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/PropertyIsDefinedChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/TextUtils.java // public final class TextUtils { // // private TextUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean equalsSafe(final String a, final String b) { // return a == null && b == null || a != null && a.equals(b); // } // // public static boolean containsIgnoreCase(final String a, final String b) { // return a != null && b != null && a.toLowerCase().contains(b.toLowerCase()); // } // // }
import com.github.vbauer.jconditions.annotation.PropertyIsDefined; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; import com.github.vbauer.jconditions.util.TextUtils;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class PropertyIsDefinedChecker implements ConditionChecker<PropertyIsDefined> { /** * {@inheritDoc} */ @Override public boolean isSatisfied(final CheckerContext<PropertyIsDefined> context) { final PropertyIsDefined annotation = context.getAnnotation(); final String[] keys = annotation.keys(); final String[] values = annotation.values(); return isSatisfied(keys, values); } private boolean isSatisfied(final String[] keys, final String[] values) { int index = 0; for (final String key : keys) { final String variable = PropUtils.getSystemProperty( PropUtils.injectProperties(key) ); try { final String value = PropUtils.injectProperties(values[index++]);
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java // public final class PropUtils { // // private static final String VAR_PREFIX = "${"; // private static final String VAR_POSTFIX = "}"; // // // private PropUtils() { // throw new UnsupportedOperationException(); // } // // // public static String getSystemProperty(final String key) { // final Map<String, String> properties = getSystemProperties(); // return properties.get(key); // } // // public static Map<String, String> getSystemProperties() { // final Map<String, String> result = new HashMap<>(); // result.putAll(System.getenv()); // result.putAll(convertPropertiesToMap(System.getProperties())); // return result; // } // // public static Map<String, String> convertPropertiesToMap(final Properties properties) { // final Map<String, String> result = new HashMap<>(); // for (final String name : properties.stringPropertyNames()) { // result.put(name, properties.getProperty(name)); // } // return result; // } // // public static String injectProperties(final String text) { // if (text != null && text.contains(VAR_PREFIX)) { // String result = text; // final Map<String, String> systemProperties = getSystemProperties(); // for (final Map.Entry<String, String> entry : systemProperties.entrySet()) { // final String key = entry.getKey(); // final String value = entry.getValue(); // result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value); // } // return result; // } // return text; // } // // public static boolean hasAnyWithProperties(final String value, final String... variants) { // for (final String operationSystem : variants) { // final String injected = injectProperties(operationSystem); // if (TextUtils.containsIgnoreCase(value, injected)) { // return true; // } // } // return false; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/util/TextUtils.java // public final class TextUtils { // // private TextUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean equalsSafe(final String a, final String b) { // return a == null && b == null || a != null && a.equals(b); // } // // public static boolean containsIgnoreCase(final String a, final String b) { // return a != null && b != null && a.toLowerCase().contains(b.toLowerCase()); // } // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/PropertyIsDefinedChecker.java import com.github.vbauer.jconditions.annotation.PropertyIsDefined; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.util.PropUtils; import com.github.vbauer.jconditions.util.TextUtils; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class PropertyIsDefinedChecker implements ConditionChecker<PropertyIsDefined> { /** * {@inheritDoc} */ @Override public boolean isSatisfied(final CheckerContext<PropertyIsDefined> context) { final PropertyIsDefined annotation = context.getAnnotation(); final String[] keys = annotation.keys(); final String[] values = annotation.values(); return isSatisfied(keys, values); } private boolean isSatisfied(final String[] keys, final String[] values) { int index = 0; for (final String key : keys) { final String variable = PropUtils.getSystemProperty( PropUtils.injectProperties(key) ); try { final String value = PropUtils.injectProperties(values[index++]);
if (!TextUtils.equalsSafe(variable, value)) {
vbauer/jconditions
src/test/java/com/github/vbauer/jconditions/util/ConstructorContractTest.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java // public final class ConditionCheckerEngine { // // private ConditionCheckerEngine() { // throw new UnsupportedOperationException(); // } // // // public static ConditionChecker<?> detectFailedChecker( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> annotations = findAllAnnotations(instance, method); // return findCheckerByAnnotations(instance, null, annotations); // } // // // private static ConditionChecker<?> findCheckerByAnnotations( // final Object instance, final Annotation parent, final Collection<Annotation> annotations // ) { // for (final Annotation annotation : annotations) { // final ConditionChecker<?> checker = // getConditionChecker(instance, parent, annotation); // // if (checker != null) { // return checker; // } // } // return null; // } // // private static ConditionChecker<?> getConditionChecker( // final Object instance, final Annotation parent, final Annotation annotation // ) { // if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // // if (annotationType == Condition.class) { // final Condition condition = (Condition) annotation; // final ConditionChecker<?> checker = // findCheckerByCondition(instance, parent, condition); // // if (checker != null) { // return checker; // } // } // // final Collection<Annotation> extra = // Arrays.asList(annotationType.getAnnotations()); // // final ConditionChecker<?> checker = // findCheckerByAnnotations(instance, annotation, extra); // // if (checker != null) { // return checker; // } // } // return null; // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // private static <T> ConditionChecker<T> findCheckerByCondition( // final T instance, final Annotation parent, final Condition condition // ) { // final Class<? extends ConditionChecker> checkerClass = condition.value(); // final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass); // final CheckerContext<T> context = new CheckerContext(instance, parent); // // if (!ConditionCheckerExecutor.isSatisfied(context, checker)) { // return checker; // } // return null; // } // // private static Collection<Annotation> findAllAnnotations( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass()); // result.addAll(Arrays.asList(method.getAnnotations())); // return result; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java // public final class ConditionCheckerExecutor { // // private ConditionCheckerExecutor() { // throw new UnsupportedOperationException(); // } // // // @SafeVarargs // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext<?> context, // final Class<? extends ConditionChecker>... checkerClasses // ) { // for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) { // if (!isSatisfied(context, checkerClass)) { // return false; // } // } // return true; // } // // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext context, // final Class<? extends ConditionChecker> checkerClass // ) { // final Object instance = context.getInstance(); // final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); // return isSatisfied(context, checker); // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // public static boolean isSatisfied( // final CheckerContext context, final ConditionChecker checker // ) { // try { // return checker.isSatisfied(context); // } catch (final Throwable ex) { // return false; // } // } // // }
import org.junit.Test; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.core.ConditionCheckerEngine; import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker;
package com.github.vbauer.jconditions.util; /** * @author Vladislav Bauer */ public class ConstructorContractTest { @Test public void testConstructors() { PrivateConstructorChecker .forClasses(
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java // public final class ConditionCheckerEngine { // // private ConditionCheckerEngine() { // throw new UnsupportedOperationException(); // } // // // public static ConditionChecker<?> detectFailedChecker( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> annotations = findAllAnnotations(instance, method); // return findCheckerByAnnotations(instance, null, annotations); // } // // // private static ConditionChecker<?> findCheckerByAnnotations( // final Object instance, final Annotation parent, final Collection<Annotation> annotations // ) { // for (final Annotation annotation : annotations) { // final ConditionChecker<?> checker = // getConditionChecker(instance, parent, annotation); // // if (checker != null) { // return checker; // } // } // return null; // } // // private static ConditionChecker<?> getConditionChecker( // final Object instance, final Annotation parent, final Annotation annotation // ) { // if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // // if (annotationType == Condition.class) { // final Condition condition = (Condition) annotation; // final ConditionChecker<?> checker = // findCheckerByCondition(instance, parent, condition); // // if (checker != null) { // return checker; // } // } // // final Collection<Annotation> extra = // Arrays.asList(annotationType.getAnnotations()); // // final ConditionChecker<?> checker = // findCheckerByAnnotations(instance, annotation, extra); // // if (checker != null) { // return checker; // } // } // return null; // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // private static <T> ConditionChecker<T> findCheckerByCondition( // final T instance, final Annotation parent, final Condition condition // ) { // final Class<? extends ConditionChecker> checkerClass = condition.value(); // final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass); // final CheckerContext<T> context = new CheckerContext(instance, parent); // // if (!ConditionCheckerExecutor.isSatisfied(context, checker)) { // return checker; // } // return null; // } // // private static Collection<Annotation> findAllAnnotations( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass()); // result.addAll(Arrays.asList(method.getAnnotations())); // return result; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java // public final class ConditionCheckerExecutor { // // private ConditionCheckerExecutor() { // throw new UnsupportedOperationException(); // } // // // @SafeVarargs // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext<?> context, // final Class<? extends ConditionChecker>... checkerClasses // ) { // for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) { // if (!isSatisfied(context, checkerClass)) { // return false; // } // } // return true; // } // // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext context, // final Class<? extends ConditionChecker> checkerClass // ) { // final Object instance = context.getInstance(); // final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); // return isSatisfied(context, checker); // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // public static boolean isSatisfied( // final CheckerContext context, final ConditionChecker checker // ) { // try { // return checker.isSatisfied(context); // } catch (final Throwable ex) { // return false; // } // } // // } // Path: src/test/java/com/github/vbauer/jconditions/util/ConstructorContractTest.java import org.junit.Test; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.core.ConditionCheckerEngine; import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker; package com.github.vbauer.jconditions.util; /** * @author Vladislav Bauer */ public class ConstructorContractTest { @Test public void testConstructors() { PrivateConstructorChecker .forClasses(
ConditionCheckerEngine.class,
vbauer/jconditions
src/test/java/com/github/vbauer/jconditions/util/ConstructorContractTest.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java // public final class ConditionCheckerEngine { // // private ConditionCheckerEngine() { // throw new UnsupportedOperationException(); // } // // // public static ConditionChecker<?> detectFailedChecker( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> annotations = findAllAnnotations(instance, method); // return findCheckerByAnnotations(instance, null, annotations); // } // // // private static ConditionChecker<?> findCheckerByAnnotations( // final Object instance, final Annotation parent, final Collection<Annotation> annotations // ) { // for (final Annotation annotation : annotations) { // final ConditionChecker<?> checker = // getConditionChecker(instance, parent, annotation); // // if (checker != null) { // return checker; // } // } // return null; // } // // private static ConditionChecker<?> getConditionChecker( // final Object instance, final Annotation parent, final Annotation annotation // ) { // if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // // if (annotationType == Condition.class) { // final Condition condition = (Condition) annotation; // final ConditionChecker<?> checker = // findCheckerByCondition(instance, parent, condition); // // if (checker != null) { // return checker; // } // } // // final Collection<Annotation> extra = // Arrays.asList(annotationType.getAnnotations()); // // final ConditionChecker<?> checker = // findCheckerByAnnotations(instance, annotation, extra); // // if (checker != null) { // return checker; // } // } // return null; // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // private static <T> ConditionChecker<T> findCheckerByCondition( // final T instance, final Annotation parent, final Condition condition // ) { // final Class<? extends ConditionChecker> checkerClass = condition.value(); // final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass); // final CheckerContext<T> context = new CheckerContext(instance, parent); // // if (!ConditionCheckerExecutor.isSatisfied(context, checker)) { // return checker; // } // return null; // } // // private static Collection<Annotation> findAllAnnotations( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass()); // result.addAll(Arrays.asList(method.getAnnotations())); // return result; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java // public final class ConditionCheckerExecutor { // // private ConditionCheckerExecutor() { // throw new UnsupportedOperationException(); // } // // // @SafeVarargs // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext<?> context, // final Class<? extends ConditionChecker>... checkerClasses // ) { // for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) { // if (!isSatisfied(context, checkerClass)) { // return false; // } // } // return true; // } // // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext context, // final Class<? extends ConditionChecker> checkerClass // ) { // final Object instance = context.getInstance(); // final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); // return isSatisfied(context, checker); // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // public static boolean isSatisfied( // final CheckerContext context, final ConditionChecker checker // ) { // try { // return checker.isSatisfied(context); // } catch (final Throwable ex) { // return false; // } // } // // }
import org.junit.Test; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.core.ConditionCheckerEngine; import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker;
package com.github.vbauer.jconditions.util; /** * @author Vladislav Bauer */ public class ConstructorContractTest { @Test public void testConstructors() { PrivateConstructorChecker .forClasses( ConditionCheckerEngine.class,
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java // public final class ConditionCheckerEngine { // // private ConditionCheckerEngine() { // throw new UnsupportedOperationException(); // } // // // public static ConditionChecker<?> detectFailedChecker( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> annotations = findAllAnnotations(instance, method); // return findCheckerByAnnotations(instance, null, annotations); // } // // // private static ConditionChecker<?> findCheckerByAnnotations( // final Object instance, final Annotation parent, final Collection<Annotation> annotations // ) { // for (final Annotation annotation : annotations) { // final ConditionChecker<?> checker = // getConditionChecker(instance, parent, annotation); // // if (checker != null) { // return checker; // } // } // return null; // } // // private static ConditionChecker<?> getConditionChecker( // final Object instance, final Annotation parent, final Annotation annotation // ) { // if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // // if (annotationType == Condition.class) { // final Condition condition = (Condition) annotation; // final ConditionChecker<?> checker = // findCheckerByCondition(instance, parent, condition); // // if (checker != null) { // return checker; // } // } // // final Collection<Annotation> extra = // Arrays.asList(annotationType.getAnnotations()); // // final ConditionChecker<?> checker = // findCheckerByAnnotations(instance, annotation, extra); // // if (checker != null) { // return checker; // } // } // return null; // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // private static <T> ConditionChecker<T> findCheckerByCondition( // final T instance, final Annotation parent, final Condition condition // ) { // final Class<? extends ConditionChecker> checkerClass = condition.value(); // final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass); // final CheckerContext<T> context = new CheckerContext(instance, parent); // // if (!ConditionCheckerExecutor.isSatisfied(context, checker)) { // return checker; // } // return null; // } // // private static Collection<Annotation> findAllAnnotations( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass()); // result.addAll(Arrays.asList(method.getAnnotations())); // return result; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java // public final class ConditionCheckerExecutor { // // private ConditionCheckerExecutor() { // throw new UnsupportedOperationException(); // } // // // @SafeVarargs // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext<?> context, // final Class<? extends ConditionChecker>... checkerClasses // ) { // for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) { // if (!isSatisfied(context, checkerClass)) { // return false; // } // } // return true; // } // // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext context, // final Class<? extends ConditionChecker> checkerClass // ) { // final Object instance = context.getInstance(); // final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); // return isSatisfied(context, checker); // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // public static boolean isSatisfied( // final CheckerContext context, final ConditionChecker checker // ) { // try { // return checker.isSatisfied(context); // } catch (final Throwable ex) { // return false; // } // } // // } // Path: src/test/java/com/github/vbauer/jconditions/util/ConstructorContractTest.java import org.junit.Test; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.core.ConditionCheckerEngine; import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker; package com.github.vbauer.jconditions.util; /** * @author Vladislav Bauer */ public class ConstructorContractTest { @Test public void testConstructors() { PrivateConstructorChecker .forClasses( ConditionCheckerEngine.class,
ConditionCheckerExecutor.class,
vbauer/jconditions
src/test/java/com/github/vbauer/jconditions/util/ConstructorContractTest.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java // public final class ConditionCheckerEngine { // // private ConditionCheckerEngine() { // throw new UnsupportedOperationException(); // } // // // public static ConditionChecker<?> detectFailedChecker( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> annotations = findAllAnnotations(instance, method); // return findCheckerByAnnotations(instance, null, annotations); // } // // // private static ConditionChecker<?> findCheckerByAnnotations( // final Object instance, final Annotation parent, final Collection<Annotation> annotations // ) { // for (final Annotation annotation : annotations) { // final ConditionChecker<?> checker = // getConditionChecker(instance, parent, annotation); // // if (checker != null) { // return checker; // } // } // return null; // } // // private static ConditionChecker<?> getConditionChecker( // final Object instance, final Annotation parent, final Annotation annotation // ) { // if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // // if (annotationType == Condition.class) { // final Condition condition = (Condition) annotation; // final ConditionChecker<?> checker = // findCheckerByCondition(instance, parent, condition); // // if (checker != null) { // return checker; // } // } // // final Collection<Annotation> extra = // Arrays.asList(annotationType.getAnnotations()); // // final ConditionChecker<?> checker = // findCheckerByAnnotations(instance, annotation, extra); // // if (checker != null) { // return checker; // } // } // return null; // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // private static <T> ConditionChecker<T> findCheckerByCondition( // final T instance, final Annotation parent, final Condition condition // ) { // final Class<? extends ConditionChecker> checkerClass = condition.value(); // final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass); // final CheckerContext<T> context = new CheckerContext(instance, parent); // // if (!ConditionCheckerExecutor.isSatisfied(context, checker)) { // return checker; // } // return null; // } // // private static Collection<Annotation> findAllAnnotations( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass()); // result.addAll(Arrays.asList(method.getAnnotations())); // return result; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java // public final class ConditionCheckerExecutor { // // private ConditionCheckerExecutor() { // throw new UnsupportedOperationException(); // } // // // @SafeVarargs // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext<?> context, // final Class<? extends ConditionChecker>... checkerClasses // ) { // for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) { // if (!isSatisfied(context, checkerClass)) { // return false; // } // } // return true; // } // // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext context, // final Class<? extends ConditionChecker> checkerClass // ) { // final Object instance = context.getInstance(); // final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); // return isSatisfied(context, checker); // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // public static boolean isSatisfied( // final CheckerContext context, final ConditionChecker checker // ) { // try { // return checker.isSatisfied(context); // } catch (final Throwable ex) { // return false; // } // } // // }
import org.junit.Test; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.core.ConditionCheckerEngine; import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker;
InOutUtils.class, NetUtils.class, PropUtils.class, ReflexUtils.class, ScriptUtils.class, TextUtils.class ) .expectedTypeOfException(UnsupportedOperationException.class) .check(); } @Test(expected = RuntimeException.class) public void testInstantiateNegativeRuntimeException() { ReflexUtils.instantiate(null, null); } @Test(expected = Exception.class) public void testInstantiateNegativeException() { ReflexUtils.instantiate(new Object(), NegativeChecker.class); } private class NegativeChecker<T> implements ConditionChecker<T> { private final boolean value; private NegativeChecker(final boolean value) { this.value = value; } @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java // public final class ConditionCheckerEngine { // // private ConditionCheckerEngine() { // throw new UnsupportedOperationException(); // } // // // public static ConditionChecker<?> detectFailedChecker( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> annotations = findAllAnnotations(instance, method); // return findCheckerByAnnotations(instance, null, annotations); // } // // // private static ConditionChecker<?> findCheckerByAnnotations( // final Object instance, final Annotation parent, final Collection<Annotation> annotations // ) { // for (final Annotation annotation : annotations) { // final ConditionChecker<?> checker = // getConditionChecker(instance, parent, annotation); // // if (checker != null) { // return checker; // } // } // return null; // } // // private static ConditionChecker<?> getConditionChecker( // final Object instance, final Annotation parent, final Annotation annotation // ) { // if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // // if (annotationType == Condition.class) { // final Condition condition = (Condition) annotation; // final ConditionChecker<?> checker = // findCheckerByCondition(instance, parent, condition); // // if (checker != null) { // return checker; // } // } // // final Collection<Annotation> extra = // Arrays.asList(annotationType.getAnnotations()); // // final ConditionChecker<?> checker = // findCheckerByAnnotations(instance, annotation, extra); // // if (checker != null) { // return checker; // } // } // return null; // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // private static <T> ConditionChecker<T> findCheckerByCondition( // final T instance, final Annotation parent, final Condition condition // ) { // final Class<? extends ConditionChecker> checkerClass = condition.value(); // final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass); // final CheckerContext<T> context = new CheckerContext(instance, parent); // // if (!ConditionCheckerExecutor.isSatisfied(context, checker)) { // return checker; // } // return null; // } // // private static Collection<Annotation> findAllAnnotations( // final Object instance, final FrameworkMethod method // ) { // final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass()); // result.addAll(Arrays.asList(method.getAnnotations())); // return result; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java // public final class ConditionCheckerExecutor { // // private ConditionCheckerExecutor() { // throw new UnsupportedOperationException(); // } // // // @SafeVarargs // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext<?> context, // final Class<? extends ConditionChecker>... checkerClasses // ) { // for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) { // if (!isSatisfied(context, checkerClass)) { // return false; // } // } // return true; // } // // @SuppressWarnings("rawtypes") // public static boolean isSatisfied( // final CheckerContext context, // final Class<? extends ConditionChecker> checkerClass // ) { // final Object instance = context.getInstance(); // final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); // return isSatisfied(context, checker); // } // // @SuppressWarnings({"unchecked", "rawtypes"}) // public static boolean isSatisfied( // final CheckerContext context, final ConditionChecker checker // ) { // try { // return checker.isSatisfied(context); // } catch (final Throwable ex) { // return false; // } // } // // } // Path: src/test/java/com/github/vbauer/jconditions/util/ConstructorContractTest.java import org.junit.Test; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import com.github.vbauer.jconditions.core.ConditionCheckerEngine; import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; import com.pushtorefresh.private_constructor_checker.PrivateConstructorChecker; InOutUtils.class, NetUtils.class, PropUtils.class, ReflexUtils.class, ScriptUtils.class, TextUtils.class ) .expectedTypeOfException(UnsupportedOperationException.class) .check(); } @Test(expected = RuntimeException.class) public void testInstantiateNegativeRuntimeException() { ReflexUtils.instantiate(null, null); } @Test(expected = Exception.class) public void testInstantiateNegativeException() { ReflexUtils.instantiate(new Object(), NegativeChecker.class); } private class NegativeChecker<T> implements ConditionChecker<T> { private final boolean value; private NegativeChecker(final boolean value) { this.value = value; } @Override
public boolean isSatisfied(final CheckerContext<T> context) {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/checker/HasFreeSpaceChecker.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // }
import com.github.vbauer.jconditions.annotation.HasFreeSpace; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import java.io.File;
package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class HasFreeSpaceChecker implements ConditionChecker<HasFreeSpace> { /** * {@inheritDoc} */ @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // Path: src/main/java/com/github/vbauer/jconditions/checker/HasFreeSpaceChecker.java import com.github.vbauer.jconditions.annotation.HasFreeSpace; import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; import java.io.File; package com.github.vbauer.jconditions.checker; /** * @author Vladislav Bauer */ public class HasFreeSpaceChecker implements ConditionChecker<HasFreeSpace> { /** * {@inheritDoc} */ @Override
public boolean isSatisfied(final CheckerContext<HasFreeSpace> context) {
vbauer/jconditions
src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java
// Path: src/main/java/com/github/vbauer/jconditions/util/ReflexUtils.java // public final class ReflexUtils { // // private static final String PACKAGE_JAVA_LANG_ANNOTATION = "java.lang.annotation"; // // // private ReflexUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean isInJavaLangAnnotationPackage(final Annotation annotation) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // final String annotationTypeName = annotationType.getName(); // return annotationTypeName.startsWith(PACKAGE_JAVA_LANG_ANNOTATION); // } // // @SuppressWarnings("unchecked") // public static <T> T getFieldValue(final Object object, final String fieldName) { // try { // final Class<?> objectClass = object.getClass(); // final Field field = objectClass.getDeclaredField(fieldName); // field.setAccessible(true); // return (T) field.get(object); // } catch (final Exception ex) { // return null; // } // } // // public static <T extends AccessibleObject> T makeAccessible(final T object) { // if (!object.isAccessible()) { // object.setAccessible(true); // } // return object; // } // // public static Collection<Annotation> findAllAnnotations(final Class<?> clazz) { // final List<Annotation> result = new ArrayList<>(); // Class<?> current = clazz; // // while (current != Object.class && current != null) { // final Class<?>[] interfaces = current.getInterfaces(); // for (final Class<?> i : interfaces) { // result.addAll(findAllAnnotations(i)); // } // // result.addAll(Arrays.asList(current.getAnnotations())); // current = current.getSuperclass(); // } // return result; // } // // public static <T> T instantiate(final Object instance, final Class<T> checkerClass) { // try { // return instantiateImpl(instance, checkerClass); // } catch (final RuntimeException ex) { // throw ex; // } catch (final Exception ex) { // throw new RuntimeException(ex); // } // } // // // private static <T> T instantiateImpl(final Object instance, final Class<T> clazz) throws Exception { // if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) { // return instantiateInnerClass(instance, clazz); // } // return instantiateClass(clazz); // } // // private static <T> T instantiateClass(final Class<T> clazz) throws Exception { // final Constructor<T> constructor = clazz.getDeclaredConstructor(); // return ReflexUtils.makeAccessible(constructor).newInstance(); // } // // private static <T> T instantiateInnerClass( // final Object instance, final Class<T> clazz // ) throws Exception { // final Class<?> outerClass = clazz.getDeclaringClass(); // final Constructor<T> constructor = clazz.getDeclaredConstructor(outerClass); // return ReflexUtils.makeAccessible(constructor).newInstance(instance); // } // // }
import com.github.vbauer.jconditions.util.ReflexUtils; import org.junit.runners.model.FrameworkMethod; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collection;
package com.github.vbauer.jconditions.core; /** * @author Vladislav Bauer */ public final class ConditionCheckerEngine { private ConditionCheckerEngine() { throw new UnsupportedOperationException(); } public static ConditionChecker<?> detectFailedChecker( final Object instance, final FrameworkMethod method ) { final Collection<Annotation> annotations = findAllAnnotations(instance, method); return findCheckerByAnnotations(instance, null, annotations); } private static ConditionChecker<?> findCheckerByAnnotations( final Object instance, final Annotation parent, final Collection<Annotation> annotations ) { for (final Annotation annotation : annotations) { final ConditionChecker<?> checker = getConditionChecker(instance, parent, annotation); if (checker != null) { return checker; } } return null; } private static ConditionChecker<?> getConditionChecker( final Object instance, final Annotation parent, final Annotation annotation ) {
// Path: src/main/java/com/github/vbauer/jconditions/util/ReflexUtils.java // public final class ReflexUtils { // // private static final String PACKAGE_JAVA_LANG_ANNOTATION = "java.lang.annotation"; // // // private ReflexUtils() { // throw new UnsupportedOperationException(); // } // // // public static boolean isInJavaLangAnnotationPackage(final Annotation annotation) { // final Class<? extends Annotation> annotationType = annotation.annotationType(); // final String annotationTypeName = annotationType.getName(); // return annotationTypeName.startsWith(PACKAGE_JAVA_LANG_ANNOTATION); // } // // @SuppressWarnings("unchecked") // public static <T> T getFieldValue(final Object object, final String fieldName) { // try { // final Class<?> objectClass = object.getClass(); // final Field field = objectClass.getDeclaredField(fieldName); // field.setAccessible(true); // return (T) field.get(object); // } catch (final Exception ex) { // return null; // } // } // // public static <T extends AccessibleObject> T makeAccessible(final T object) { // if (!object.isAccessible()) { // object.setAccessible(true); // } // return object; // } // // public static Collection<Annotation> findAllAnnotations(final Class<?> clazz) { // final List<Annotation> result = new ArrayList<>(); // Class<?> current = clazz; // // while (current != Object.class && current != null) { // final Class<?>[] interfaces = current.getInterfaces(); // for (final Class<?> i : interfaces) { // result.addAll(findAllAnnotations(i)); // } // // result.addAll(Arrays.asList(current.getAnnotations())); // current = current.getSuperclass(); // } // return result; // } // // public static <T> T instantiate(final Object instance, final Class<T> checkerClass) { // try { // return instantiateImpl(instance, checkerClass); // } catch (final RuntimeException ex) { // throw ex; // } catch (final Exception ex) { // throw new RuntimeException(ex); // } // } // // // private static <T> T instantiateImpl(final Object instance, final Class<T> clazz) throws Exception { // if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) { // return instantiateInnerClass(instance, clazz); // } // return instantiateClass(clazz); // } // // private static <T> T instantiateClass(final Class<T> clazz) throws Exception { // final Constructor<T> constructor = clazz.getDeclaredConstructor(); // return ReflexUtils.makeAccessible(constructor).newInstance(); // } // // private static <T> T instantiateInnerClass( // final Object instance, final Class<T> clazz // ) throws Exception { // final Class<?> outerClass = clazz.getDeclaringClass(); // final Constructor<T> constructor = clazz.getDeclaredConstructor(outerClass); // return ReflexUtils.makeAccessible(constructor).newInstance(instance); // } // // } // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java import com.github.vbauer.jconditions.util.ReflexUtils; import org.junit.runners.model.FrameworkMethod; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collection; package com.github.vbauer.jconditions.core; /** * @author Vladislav Bauer */ public final class ConditionCheckerEngine { private ConditionCheckerEngine() { throw new UnsupportedOperationException(); } public static ConditionChecker<?> detectFailedChecker( final Object instance, final FrameworkMethod method ) { final Collection<Annotation> annotations = findAllAnnotations(instance, method); return findCheckerByAnnotations(instance, null, annotations); } private static ConditionChecker<?> findCheckerByAnnotations( final Object instance, final Annotation parent, final Collection<Annotation> annotations ) { for (final Annotation annotation : annotations) { final ConditionChecker<?> checker = getConditionChecker(instance, parent, annotation); if (checker != null) { return checker; } } return null; } private static ConditionChecker<?> getConditionChecker( final Object instance, final Annotation parent, final Annotation annotation ) {
if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) {
vbauer/jconditions
src/test/java/com/github/vbauer/jconditions/misc/Always.java
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // }
import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker;
package com.github.vbauer.jconditions.misc; /** * @author Vladislav Bauer */ public class Always<T> implements ConditionChecker<T> { @Override
// Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java // public class CheckerContext<T> { // // private final Object instance; // private final T annotation; // // // public CheckerContext(final Object instance, final T annotation) { // this.instance = instance; // this.annotation = annotation; // } // // // public Object getInstance() { // return instance; // } // // public T getAnnotation() { // return annotation; // } // // } // // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java // public interface ConditionChecker<T> { // // /** // * Checks if execution of test method should be continued or not. // * // * @param context input data for checker // * @return true if execution should be continued and false - otherwise // * @throws Exception on any error (it is the same as false in return value) // */ // boolean isSatisfied(CheckerContext<T> context) throws Exception; // // } // Path: src/test/java/com/github/vbauer/jconditions/misc/Always.java import com.github.vbauer.jconditions.core.CheckerContext; import com.github.vbauer.jconditions.core.ConditionChecker; package com.github.vbauer.jconditions.misc; /** * @author Vladislav Bauer */ public class Always<T> implements ConditionChecker<T> { @Override
public boolean isSatisfied(final CheckerContext<T> context) {
r1chardj0n3s/pycode-minecraft
src/main/java/net/mechanicalcat/pycode/script/MyEntityPlayers.java
// Path: src/main/java/net/mechanicalcat/pycode/script/MyEntityPlayer.java // public class MyEntityPlayer extends MyEntityLiving { // public String name; // // public MyEntityPlayer(EntityPlayer player) { // super(player); // this.name = player.getName(); // } // // @Override // public boolean isPlayer() { // return true; // } // public boolean isMob() { // return false; // } // // public String toString() { // return this.name; // } // // public void chat(Object... args) { // if (this.entity.worldObj == null || !this.entity.worldObj.isRemote) return; // StringBuilder sbStr = new StringBuilder(); // for (Object arg : args) { // if (arg != args[0]) sbStr.append(" "); // sbStr.append(arg); // } // ((EntityPlayer) this.entity).addChatComponentMessage(new TextComponentString(sbStr.toString())); // } // // public void giveAchievement(String name) throws CommandException { // if (!name.contains(".")) { // name = "achievement." + name; // } // this.achiev("give", name); // } // // public void takeAchievement(String name) throws CommandException { // if (!name.contains(".")) { // name = "achievement." + name; // } // this.achiev("take", name); // } // // private void achiev(String... args) throws CommandException { // if (this.entity.worldObj == null || this.entity.worldObj.isRemote) return; // new CommandAchievement().execute(this.entity.worldObj.getMinecraftServer(), this.entity, // args); // } // }
import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.LinkedList; import java.util.List; import net.mechanicalcat.pycode.script.MyEntityPlayer; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.PlayerNotFoundException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos;
/* * Copyright (c) 2017 Richard Jones <richard@mechanicalcat.net> * All Rights Reserved * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package net.mechanicalcat.pycode.script; public class MyEntityPlayers { World world; public MyEntityPlayers(World world) { this.world = world; }
// Path: src/main/java/net/mechanicalcat/pycode/script/MyEntityPlayer.java // public class MyEntityPlayer extends MyEntityLiving { // public String name; // // public MyEntityPlayer(EntityPlayer player) { // super(player); // this.name = player.getName(); // } // // @Override // public boolean isPlayer() { // return true; // } // public boolean isMob() { // return false; // } // // public String toString() { // return this.name; // } // // public void chat(Object... args) { // if (this.entity.worldObj == null || !this.entity.worldObj.isRemote) return; // StringBuilder sbStr = new StringBuilder(); // for (Object arg : args) { // if (arg != args[0]) sbStr.append(" "); // sbStr.append(arg); // } // ((EntityPlayer) this.entity).addChatComponentMessage(new TextComponentString(sbStr.toString())); // } // // public void giveAchievement(String name) throws CommandException { // if (!name.contains(".")) { // name = "achievement." + name; // } // this.achiev("give", name); // } // // public void takeAchievement(String name) throws CommandException { // if (!name.contains(".")) { // name = "achievement." + name; // } // this.achiev("take", name); // } // // private void achiev(String... args) throws CommandException { // if (this.entity.worldObj == null || this.entity.worldObj.isRemote) return; // new CommandAchievement().execute(this.entity.worldObj.getMinecraftServer(), this.entity, // args); // } // } // Path: src/main/java/net/mechanicalcat/pycode/script/MyEntityPlayers.java import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.LinkedList; import java.util.List; import net.mechanicalcat.pycode.script.MyEntityPlayer; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.PlayerNotFoundException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; /* * Copyright (c) 2017 Richard Jones <richard@mechanicalcat.net> * All Rights Reserved * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package net.mechanicalcat.pycode.script; public class MyEntityPlayers { World world; public MyEntityPlayers(World world) { this.world = world; }
public MyEntityPlayer[] all() {
r1chardj0n3s/pycode-minecraft
src/main/java/net/mechanicalcat/pycode/script/PythonCode.java
// Path: src/main/java/net/mechanicalcat/pycode/PythonEngine.java // public class PythonEngine { // private static PythonEngine instance = null; // private PyScriptEngine engine; // // private PythonEngine() { // ScriptEngineManager manager = new ScriptEngineManager(); // engine = (PyScriptEngine) manager.getEngineByName("python"); // if (engine == null) { // FMLLog.severe("FAILED to getBlock Python"); // } else { // FMLLog.fine("Got Python"); // } // try { // engine.eval("print 'Python Ready'"); // } catch (ScriptException e) { // FMLLog.severe("Python failed: %s", e); // } // } // // public static PythonEngine getEngine() { // if (instance == null) { // instance = new PythonEngine(); // } // return instance; // } // // public static CompiledScript compile(String code) throws ScriptException { // return getEngine().engine.compile(code); // } // // public static Object eval(String code, ScriptContext context) throws ScriptException { // return getEngine().engine.eval(code, context); // } // }
import net.mechanicalcat.pycode.PythonEngine; import net.minecraft.command.ICommandSender; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.FMLLog; import org.python.core.Py; import org.python.core.PyFunction; import org.python.core.PyObject; import javax.annotation.Nullable; import javax.script.*; import java.io.PrintWriter; import java.io.StringWriter; import java.util.HashMap; import java.util.LinkedList; import java.util.List;
/* * Copyright (c) 2017 Richard Jones <richard@mechanicalcat.net> * All Rights Reserved * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package net.mechanicalcat.pycode.script; public class PythonCode { private String code = ""; private boolean codeChanged = false; private SimpleScriptContext context; private Bindings bindings; private World world = null; private BlockPos pos; private ICommandSender runner; public static String CODE_NBT_TAG = "code"; public MyEntityPlayers players; public PythonCode() { this.context = new SimpleScriptContext(); this.bindings = new SimpleBindings(); this.context.setBindings(this.bindings, ScriptContext.ENGINE_SCOPE); } public String getCode() {return code;} public boolean hasCode() {return !code.isEmpty();} public void check(String code) throws ScriptException {
// Path: src/main/java/net/mechanicalcat/pycode/PythonEngine.java // public class PythonEngine { // private static PythonEngine instance = null; // private PyScriptEngine engine; // // private PythonEngine() { // ScriptEngineManager manager = new ScriptEngineManager(); // engine = (PyScriptEngine) manager.getEngineByName("python"); // if (engine == null) { // FMLLog.severe("FAILED to getBlock Python"); // } else { // FMLLog.fine("Got Python"); // } // try { // engine.eval("print 'Python Ready'"); // } catch (ScriptException e) { // FMLLog.severe("Python failed: %s", e); // } // } // // public static PythonEngine getEngine() { // if (instance == null) { // instance = new PythonEngine(); // } // return instance; // } // // public static CompiledScript compile(String code) throws ScriptException { // return getEngine().engine.compile(code); // } // // public static Object eval(String code, ScriptContext context) throws ScriptException { // return getEngine().engine.eval(code, context); // } // } // Path: src/main/java/net/mechanicalcat/pycode/script/PythonCode.java import net.mechanicalcat.pycode.PythonEngine; import net.minecraft.command.ICommandSender; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.FMLLog; import org.python.core.Py; import org.python.core.PyFunction; import org.python.core.PyObject; import javax.annotation.Nullable; import javax.script.*; import java.io.PrintWriter; import java.io.StringWriter; import java.util.HashMap; import java.util.LinkedList; import java.util.List; /* * Copyright (c) 2017 Richard Jones <richard@mechanicalcat.net> * All Rights Reserved * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package net.mechanicalcat.pycode.script; public class PythonCode { private String code = ""; private boolean codeChanged = false; private SimpleScriptContext context; private Bindings bindings; private World world = null; private BlockPos pos; private ICommandSender runner; public static String CODE_NBT_TAG = "code"; public MyEntityPlayers players; public PythonCode() { this.context = new SimpleScriptContext(); this.bindings = new SimpleBindings(); this.context.setBindings(this.bindings, ScriptContext.ENGINE_SCOPE); } public String getCode() {return code;} public boolean hasCode() {return !code.isEmpty();} public void check(String code) throws ScriptException {
PythonEngine.compile(code);
r1chardj0n3s/pycode-minecraft
src/main/java/net/mechanicalcat/pycode/init/ModBlocks.java
// Path: src/main/java/net/mechanicalcat/pycode/blocks/PythonBlock.java // public final class PythonBlock extends Block implements ITileEntityProvider { // public PythonBlock() { // super(Material.CLAY); // setUnlocalizedName(Reference.PyCodeRegistrations.BLOCK.getUnlocalizedName()); // setRegistryName(Reference.PyCodeRegistrations.BLOCK.getRegistryName()); // setCreativeTab(CreativeTabs.BUILDING_BLOCKS); // setHardness(1.0f); // } // // @Override // public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, // @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { // FMLLog.info("onBlockActivated item=%s", heldItem); // PyCodeBlockTileEntity code_block = this.getEntity(world, pos); // return code_block == null || code_block.handleItemInteraction(playerIn, heldItem); // } // // @Override // public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { // super.onBlockPlacedBy(world, pos, state, placer, stack); // PyCodeBlockTileEntity code_block = this.getEntity(world, pos); // if (code_block != null && stack.hasTagCompound()) { // code_block.readFromNBT(stack.getTagCompound()); // code_block.getCode().setContext(world, code_block, pos); // } // } // // @Nullable // private PyCodeBlockTileEntity getEntity(World world, BlockPos pos) { // TileEntity entity = world.getTileEntity(pos); // if (entity instanceof PyCodeBlockTileEntity) { // return (PyCodeBlockTileEntity) entity; // } // return null; // } // // @Override // public TileEntity createNewTileEntity(World world, int meta) { // return new PyCodeBlockTileEntity(); // } // // @Override // public void onEntityWalk(World world, BlockPos pos, Entity entity) { // PyCodeBlockTileEntity code_block = this.getEntity(world, pos); // if (entity instanceof EntityPlayer && code_block.getCode().hasKey("onPlayerWalk")) { // code_block.handleEntityInteraction(new MyEntityPlayer((EntityPlayer) entity), "onPlayerWalk"); // } else if (entity instanceof EntityLivingBase) { // if (code_block.getCode().hasKey("onEntityWalk")) { // code_block.handleEntityInteraction(new MyEntityLiving((EntityLivingBase) entity), "onEntityWalk"); // } // } // } // // public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { // PyCodeBlockTileEntity entity = this.getEntity(worldIn, pos); // // if (entity != null && !entity.getCode().getCode().isEmpty()) { // ItemStack itemstack = this.createStackedBlock(state); // if (!itemstack.hasTagCompound()) { // itemstack.setTagCompound(new NBTTagCompound()); // } // entity.writeToNBT(itemstack.getTagCompound()); // spawnAsEntity(worldIn, pos, itemstack); // } // // super.breakBlock(worldIn, pos, state); // } // // @Nullable // @Override // public Item getItemDropped(IBlockState state, Random rand, int fortune) { // // we're already dropping the item in breakBlock() // return null; // } // // // public int tickRate(World world) { // // return 10; // // } // // // public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) // // canProvidePower // // // // // @Override // // public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) { // // super.onNeighborChange(world, pos, neighbor); // // } // } // // Path: src/main/java/net/mechanicalcat/pycode/items/PythonBlockItem.java // public class PythonBlockItem extends ItemBlock { // public PythonBlockItem(PythonBlock block) {super(block);} // // @Override // public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { // NBTTagCompound compound = stack.getTagCompound(); // if (compound == null) return; // if (compound.hasKey(PythonCode.CODE_NBT_TAG)) tooltip.add("[has code]"); // } // }
import net.minecraftforge.fml.common.registry.GameRegistry; import net.mechanicalcat.pycode.blocks.PythonBlock; import net.mechanicalcat.pycode.items.PythonBlockItem; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock;
/* * Copyright (c) 2017 Richard Jones <richard@mechanicalcat.net> * All Rights Reserved * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package net.mechanicalcat.pycode.init; public final class ModBlocks { public static PythonBlock python_block;
// Path: src/main/java/net/mechanicalcat/pycode/blocks/PythonBlock.java // public final class PythonBlock extends Block implements ITileEntityProvider { // public PythonBlock() { // super(Material.CLAY); // setUnlocalizedName(Reference.PyCodeRegistrations.BLOCK.getUnlocalizedName()); // setRegistryName(Reference.PyCodeRegistrations.BLOCK.getRegistryName()); // setCreativeTab(CreativeTabs.BUILDING_BLOCKS); // setHardness(1.0f); // } // // @Override // public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, // @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { // FMLLog.info("onBlockActivated item=%s", heldItem); // PyCodeBlockTileEntity code_block = this.getEntity(world, pos); // return code_block == null || code_block.handleItemInteraction(playerIn, heldItem); // } // // @Override // public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { // super.onBlockPlacedBy(world, pos, state, placer, stack); // PyCodeBlockTileEntity code_block = this.getEntity(world, pos); // if (code_block != null && stack.hasTagCompound()) { // code_block.readFromNBT(stack.getTagCompound()); // code_block.getCode().setContext(world, code_block, pos); // } // } // // @Nullable // private PyCodeBlockTileEntity getEntity(World world, BlockPos pos) { // TileEntity entity = world.getTileEntity(pos); // if (entity instanceof PyCodeBlockTileEntity) { // return (PyCodeBlockTileEntity) entity; // } // return null; // } // // @Override // public TileEntity createNewTileEntity(World world, int meta) { // return new PyCodeBlockTileEntity(); // } // // @Override // public void onEntityWalk(World world, BlockPos pos, Entity entity) { // PyCodeBlockTileEntity code_block = this.getEntity(world, pos); // if (entity instanceof EntityPlayer && code_block.getCode().hasKey("onPlayerWalk")) { // code_block.handleEntityInteraction(new MyEntityPlayer((EntityPlayer) entity), "onPlayerWalk"); // } else if (entity instanceof EntityLivingBase) { // if (code_block.getCode().hasKey("onEntityWalk")) { // code_block.handleEntityInteraction(new MyEntityLiving((EntityLivingBase) entity), "onEntityWalk"); // } // } // } // // public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { // PyCodeBlockTileEntity entity = this.getEntity(worldIn, pos); // // if (entity != null && !entity.getCode().getCode().isEmpty()) { // ItemStack itemstack = this.createStackedBlock(state); // if (!itemstack.hasTagCompound()) { // itemstack.setTagCompound(new NBTTagCompound()); // } // entity.writeToNBT(itemstack.getTagCompound()); // spawnAsEntity(worldIn, pos, itemstack); // } // // super.breakBlock(worldIn, pos, state); // } // // @Nullable // @Override // public Item getItemDropped(IBlockState state, Random rand, int fortune) { // // we're already dropping the item in breakBlock() // return null; // } // // // public int tickRate(World world) { // // return 10; // // } // // // public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) // // canProvidePower // // // // // @Override // // public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) { // // super.onNeighborChange(world, pos, neighbor); // // } // } // // Path: src/main/java/net/mechanicalcat/pycode/items/PythonBlockItem.java // public class PythonBlockItem extends ItemBlock { // public PythonBlockItem(PythonBlock block) {super(block);} // // @Override // public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { // NBTTagCompound compound = stack.getTagCompound(); // if (compound == null) return; // if (compound.hasKey(PythonCode.CODE_NBT_TAG)) tooltip.add("[has code]"); // } // } // Path: src/main/java/net/mechanicalcat/pycode/init/ModBlocks.java import net.minecraftforge.fml.common.registry.GameRegistry; import net.mechanicalcat.pycode.blocks.PythonBlock; import net.mechanicalcat.pycode.items.PythonBlockItem; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; /* * Copyright (c) 2017 Richard Jones <richard@mechanicalcat.net> * All Rights Reserved * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ package net.mechanicalcat.pycode.init; public final class ModBlocks { public static PythonBlock python_block;
public static PythonBlockItem python_block_item;
SecrecySupportTeam/Secrecy_fDroid_DEPRECIATED
app/src/main/java/com/doplgangr/secrecy/OutgoingCallReceiver.java
// Path: app/src/main/java/com/doplgangr/secrecy/Premium/StealthMode.java // public class StealthMode { // // //Hides the app here. // //Set the counter to 1, prevent appearance of first time alert in the future // //Set LauncherActivity to disabled, removing launcher icon. // public static void hideApp(final Context context) { // // ComponentName componentToDisable = // new ComponentName(context.getPackageName(), // LauncherActivity_.class.getName()); // if (context.getPackageManager() != null) // context.getPackageManager() // .setComponentEnabledSetting(componentToDisable, // PackageManager.COMPONENT_ENABLED_STATE_DISABLED, // PackageManager.DONT_KILL_APP); // } // // public static void showApp(final Context context) { // // ComponentName componentToDisable = // new ComponentName(context.getPackageName(), // LauncherActivity_.class.getName()); // if (context.getPackageManager() != null) // context.getPackageManager() // .setComponentEnabledSetting(componentToDisable, // PackageManager.COMPONENT_ENABLED_STATE_ENABLED, // PackageManager.DONT_KILL_APP); // } // }
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.v4.content.IntentCompat; import com.doplgangr.secrecy.Premium.StealthMode; import com.doplgangr.secrecy.Settings.Prefs_; import com.doplgangr.secrecy.Views.MainActivity_; import org.androidannotations.annotations.EReceiver; import org.androidannotations.annotations.sharedpreferences.Pref;
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ package com.doplgangr.secrecy; @EReceiver public class OutgoingCallReceiver extends BroadcastReceiver { @Pref Prefs_ Pref; @Override public void onReceive(final Context context, Intent intent) { // Gets the intent, check if it matches our secret code if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction()) && intent.getExtras() != null) { Intent launcher = new Intent(context, MainActivity_.class); //These flags are added to make the new mainActivity in the home stack. //i.e. back button returns to home not dialer. launcher.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME); String phoneNumber = intent.getExtras().getString(android.content.Intent.EXTRA_PHONE_NUMBER); if (Pref.OpenPIN().exists()) if (("*#" + Pref.OpenPIN().get()).equals(phoneNumber)) // Launch the main app!! launchActivity(context, launcher); } } void launchActivity(Context context, Intent launcher) { //Try hiding app everytime, prevent reappearance of app icon.
// Path: app/src/main/java/com/doplgangr/secrecy/Premium/StealthMode.java // public class StealthMode { // // //Hides the app here. // //Set the counter to 1, prevent appearance of first time alert in the future // //Set LauncherActivity to disabled, removing launcher icon. // public static void hideApp(final Context context) { // // ComponentName componentToDisable = // new ComponentName(context.getPackageName(), // LauncherActivity_.class.getName()); // if (context.getPackageManager() != null) // context.getPackageManager() // .setComponentEnabledSetting(componentToDisable, // PackageManager.COMPONENT_ENABLED_STATE_DISABLED, // PackageManager.DONT_KILL_APP); // } // // public static void showApp(final Context context) { // // ComponentName componentToDisable = // new ComponentName(context.getPackageName(), // LauncherActivity_.class.getName()); // if (context.getPackageManager() != null) // context.getPackageManager() // .setComponentEnabledSetting(componentToDisable, // PackageManager.COMPONENT_ENABLED_STATE_ENABLED, // PackageManager.DONT_KILL_APP); // } // } // Path: app/src/main/java/com/doplgangr/secrecy/OutgoingCallReceiver.java import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.v4.content.IntentCompat; import com.doplgangr.secrecy.Premium.StealthMode; import com.doplgangr.secrecy.Settings.Prefs_; import com.doplgangr.secrecy.Views.MainActivity_; import org.androidannotations.annotations.EReceiver; import org.androidannotations.annotations.sharedpreferences.Pref; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ package com.doplgangr.secrecy; @EReceiver public class OutgoingCallReceiver extends BroadcastReceiver { @Pref Prefs_ Pref; @Override public void onReceive(final Context context, Intent intent) { // Gets the intent, check if it matches our secret code if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction()) && intent.getExtras() != null) { Intent launcher = new Intent(context, MainActivity_.class); //These flags are added to make the new mainActivity in the home stack. //i.e. back button returns to home not dialer. launcher.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME); String phoneNumber = intent.getExtras().getString(android.content.Intent.EXTRA_PHONE_NUMBER); if (Pref.OpenPIN().exists()) if (("*#" + Pref.OpenPIN().get()).equals(phoneNumber)) // Launch the main app!! launchActivity(context, launcher); } } void launchActivity(Context context, Intent launcher) { //Try hiding app everytime, prevent reappearance of app icon.
StealthMode.hideApp(context);
SecrecySupportTeam/Secrecy_fDroid_DEPRECIATED
app/src/main/java/com/doplgangr/secrecy/Jobs/ShredFileJob.java
// Path: app/src/main/java/com/doplgangr/secrecy/Util.java // public class Util { // public static final DialogInterface.OnClickListener emptyClickListener = new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialogInterface, int i) { // } // }; // // public static void alert(final Context context, // final String title, final String message, // final DialogInterface.OnClickListener positive, // final DialogInterface.OnClickListener negative) { // new Handler(Looper.getMainLooper()).post(new Runnable() { // // // @Override // public void run() { // AlertDialog.Builder a = new AlertDialog.Builder(context); // if (title != null) // a.setTitle(title); // if (message != null) // a.setMessage(message); // if (positive != null) // a.setPositiveButton(context.getString(R.string.OK), positive); // if (negative != null) // a.setNegativeButton(context.getString(R.string.CANCEL), negative); // a.setCancelable(false); // a.show(); // } // // }); // } // // public static void toast(final Activity context, final String msg, final Integer duration) { // context.runOnUiThread(new Runnable() { // public void run() { // Toast.makeText(context, msg, duration).show(); // } // }); // } // // public static void log(Object... objects) { // String log = ""; // for (Object object : objects) // log += " " + object; // Log.d("SecrecyLogs", log); // } // // public static Map<String, java.io.File> getAllStorageLocations() { // Map<String, java.io.File> map = new TreeMap<String, File>(); // // List<String> mMounts = new ArrayList<String>(99); // //List<String> mVold = new ArrayList<String>(99); // mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); // try { // java.io.File mountFile = new java.io.File("/proc/mounts"); // if (mountFile.exists()) { // Scanner scanner = new Scanner(mountFile); // while (scanner.hasNext()) { // String line = scanner.nextLine(); // //if (line.startsWith("/dev/block/vold/")) { // String[] lineElements = line.split(" "); // String element = lineElements[1]; // mMounts.add(element); // } // } // } catch (Exception e) { // e.printStackTrace(); // } // /** // try { // java.io.File voldFile = new java.io.File("/system/etc/vold.fstab"); // if (voldFile.exists()) { // Scanner scanner = new Scanner(voldFile); // while (scanner.hasNext()) { // String line = scanner.nextLine(); // //if (line.startsWith("dev_mount")) { // String[] lineElements = line.split(" "); // String element = lineElements[2]; // // if (element.contains(":")) // element = element.substring(0, element.indexOf(":")); // mVold.add(element); // } // } // } catch (Exception e) { // e.printStackTrace(); // } // **/ // // /* // for (int i = 0; i < mMounts.size(); i++) { // String mount = mMounts.get(i); // if (!mVold.contains(mount)) // mMounts.remove(i--); // } // mVold.clear(); // */ // // List<String> mountHash = new ArrayList<String>(99); // // for (String mount : mMounts) { // java.io.File root = new java.io.File(mount); // Util.log(mount, "is checked"); // Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); // if (canWrite(root)) { // Util.log(mount, "is writable"); // java.io.File[] list = root.listFiles(); // String hash = "["; // if (list != null) // for (java.io.File f : list) // hash += f.getName().hashCode() + ":" + f.length() + ", "; // hash += "]"; // if (!mountHash.contains(hash)) { // String key = root.getAbsolutePath() + " (" + org.apache.commons.io // .FileUtils.byteCountToDisplaySize( // root.getUsableSpace() // ) + " free space)"; // mountHash.add(hash); // map.put(key, root); // } // } // } // // mMounts.clear(); // return map; // } // // public static Boolean canWrite(java.io.File root) { // if (root == null) // return false; // if (!root.exists()) // return false; // if (!root.isDirectory()) // return false; // try { // java.io.File file = File.createTempFile("TEMP", null, root); // return file.delete(); // } catch (Exception e) { // //Failed to create files // return false; // } // // } // // public static void openURI(String uri) { // Intent i = new Intent(Intent.ACTION_VIEW); // i.setData(Uri.parse(uri)); // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // CustomApp.context.startActivity(i); // // } // }
import com.doplgangr.secrecy.Util; import com.path.android.jobqueue.Job; import com.path.android.jobqueue.Params; import java.io.BufferedOutputStream; import java.io.OutputStream;
package com.doplgangr.secrecy.Jobs; public class ShredFileJob extends Job { public static final int PRIORITY = 1; private OutputStream fileOs = null; private long size; public ShredFileJob(OutputStream os, long size) { super(new Params(PRIORITY)); this.fileOs = os; this.size = size; } @Override public void onAdded() { } @Override public void onRun() throws Throwable {
// Path: app/src/main/java/com/doplgangr/secrecy/Util.java // public class Util { // public static final DialogInterface.OnClickListener emptyClickListener = new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialogInterface, int i) { // } // }; // // public static void alert(final Context context, // final String title, final String message, // final DialogInterface.OnClickListener positive, // final DialogInterface.OnClickListener negative) { // new Handler(Looper.getMainLooper()).post(new Runnable() { // // // @Override // public void run() { // AlertDialog.Builder a = new AlertDialog.Builder(context); // if (title != null) // a.setTitle(title); // if (message != null) // a.setMessage(message); // if (positive != null) // a.setPositiveButton(context.getString(R.string.OK), positive); // if (negative != null) // a.setNegativeButton(context.getString(R.string.CANCEL), negative); // a.setCancelable(false); // a.show(); // } // // }); // } // // public static void toast(final Activity context, final String msg, final Integer duration) { // context.runOnUiThread(new Runnable() { // public void run() { // Toast.makeText(context, msg, duration).show(); // } // }); // } // // public static void log(Object... objects) { // String log = ""; // for (Object object : objects) // log += " " + object; // Log.d("SecrecyLogs", log); // } // // public static Map<String, java.io.File> getAllStorageLocations() { // Map<String, java.io.File> map = new TreeMap<String, File>(); // // List<String> mMounts = new ArrayList<String>(99); // //List<String> mVold = new ArrayList<String>(99); // mMounts.add(Environment.getExternalStorageDirectory().getAbsolutePath()); // try { // java.io.File mountFile = new java.io.File("/proc/mounts"); // if (mountFile.exists()) { // Scanner scanner = new Scanner(mountFile); // while (scanner.hasNext()) { // String line = scanner.nextLine(); // //if (line.startsWith("/dev/block/vold/")) { // String[] lineElements = line.split(" "); // String element = lineElements[1]; // mMounts.add(element); // } // } // } catch (Exception e) { // e.printStackTrace(); // } // /** // try { // java.io.File voldFile = new java.io.File("/system/etc/vold.fstab"); // if (voldFile.exists()) { // Scanner scanner = new Scanner(voldFile); // while (scanner.hasNext()) { // String line = scanner.nextLine(); // //if (line.startsWith("dev_mount")) { // String[] lineElements = line.split(" "); // String element = lineElements[2]; // // if (element.contains(":")) // element = element.substring(0, element.indexOf(":")); // mVold.add(element); // } // } // } catch (Exception e) { // e.printStackTrace(); // } // **/ // // /* // for (int i = 0; i < mMounts.size(); i++) { // String mount = mMounts.get(i); // if (!mVold.contains(mount)) // mMounts.remove(i--); // } // mVold.clear(); // */ // // List<String> mountHash = new ArrayList<String>(99); // // for (String mount : mMounts) { // java.io.File root = new java.io.File(mount); // Util.log(mount, "is checked"); // Util.log(mount, root.exists(), root.isDirectory(), canWrite(root)); // if (canWrite(root)) { // Util.log(mount, "is writable"); // java.io.File[] list = root.listFiles(); // String hash = "["; // if (list != null) // for (java.io.File f : list) // hash += f.getName().hashCode() + ":" + f.length() + ", "; // hash += "]"; // if (!mountHash.contains(hash)) { // String key = root.getAbsolutePath() + " (" + org.apache.commons.io // .FileUtils.byteCountToDisplaySize( // root.getUsableSpace() // ) + " free space)"; // mountHash.add(hash); // map.put(key, root); // } // } // } // // mMounts.clear(); // return map; // } // // public static Boolean canWrite(java.io.File root) { // if (root == null) // return false; // if (!root.exists()) // return false; // if (!root.isDirectory()) // return false; // try { // java.io.File file = File.createTempFile("TEMP", null, root); // return file.delete(); // } catch (Exception e) { // //Failed to create files // return false; // } // // } // // public static void openURI(String uri) { // Intent i = new Intent(Intent.ACTION_VIEW); // i.setData(Uri.parse(uri)); // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // CustomApp.context.startActivity(i); // // } // } // Path: app/src/main/java/com/doplgangr/secrecy/Jobs/ShredFileJob.java import com.doplgangr.secrecy.Util; import com.path.android.jobqueue.Job; import com.path.android.jobqueue.Params; import java.io.BufferedOutputStream; import java.io.OutputStream; package com.doplgangr.secrecy.Jobs; public class ShredFileJob extends Job { public static final int PRIORITY = 1; private OutputStream fileOs = null; private long size; public ShredFileJob(OutputStream os, long size) { super(new Params(PRIORITY)); this.fileOs = os; this.size = size; } @Override public void onAdded() { } @Override public void onRun() throws Throwable {
Util.log("Shreddd");
SecrecySupportTeam/Secrecy_fDroid_DEPRECIATED
payme/src/main/java/main/java/com/github/jberkel/pay/me/PurchaseFlowState.java
// Path: payme/src/main/java/main/java/com/github/jberkel/pay/me/model/ItemType.java // public enum ItemType { // /** normal in app purchase */ // INAPP, // /** subscription */ // SUBS, // /** unknown type */ // UNKNOWN; // // public String toString() { // return name().toLowerCase(Locale.ENGLISH); // } // // public static ItemType fromString(String type) { // for (ItemType t : values()) { // if (t.toString().equals(type)) return t; // } // return UNKNOWN; // } // } // // Path: payme/src/main/java/main/java/com/github/jberkel/pay/me/model/Purchase.java // public class Purchase { // // private final String mOrderId; // private final String mPackageName; // private final String mSku; // private final long mPurchaseTime; // private final int mPurchaseState; // private final String mDeveloperPayload; // private final String mToken; // // private final ItemType mItemType; // private final State mState; // private final String mSignature; // private final String mOriginalJson; // // // /** // * @param itemType the item type for this purchase, cannot be null. // * @param jsonPurchaseInfo the JSON representation of this purchase // * @param signature the signature // * @throws JSONException if the purchase cannot be parsed or is invalid. // */ // public Purchase(ItemType itemType, String jsonPurchaseInfo, String signature) throws JSONException { // if (itemType == null) throw new IllegalArgumentException("itemType cannot be null"); // mItemType = itemType; // final JSONObject json = new JSONObject(jsonPurchaseInfo); // // mOrderId = json.optString(ORDER_ID); // mPackageName = json.optString(PACKAGE_NAME); // mSku = json.optString(PRODUCT_ID); // mPurchaseTime = json.optLong(PURCHASE_TIME); // mPurchaseState = json.optInt(PURCHASE_STATE); // mDeveloperPayload = json.optString(DEVELOPER_PAYLOAD); // mToken = json.optString(TOKEN, json.optString(PURCHASE_TOKEN)); // // mOriginalJson = jsonPurchaseInfo; // mSignature = signature; // mState = State.fromCode(mPurchaseState); // // if (TextUtils.isEmpty(mSku)) { // throw new JSONException("SKU is empty"); // } // } // // public ItemType getItemType() { // return mItemType; // } // // /** // * @return A unique order identifier for the transaction. This corresponds to the Google Wallet Order ID. // */ // public String getOrderId() { // return mOrderId; // } // // /** // * // * @return The application package from which the purchase originated. // */ // public String getPackageName() { // return mPackageName; // } // // /** // * @return The item's product identifier. Every item has a product ID, which you must specify in // * the application's product list on the Google Play Developer Console. // */ // public String getSku() { // return mSku; // } // // /** // * @return The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970). // */ // public long getPurchaseTime() { // return mPurchaseTime; // } // // /** // * @return The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded). // */ // public int getRawState() { // return mPurchaseState; // } // // /** // * @return The parsed purchase state of the order. // */ // public State getState() { // return mState; // } // // /** // * @return A developer-specified string that contains supplemental information about an order. You // * can specify a value for this field when you make a getBuyIntent request. // */ // public String getDeveloperPayload() { // return mDeveloperPayload; // } // // /** // * @return A token that uniquely identifies a purchase for a given item and user pair. // */ // public String getToken() { // return mToken; // } // // /** // * @return the original JSON response, as received from the billing service. // */ // public String getOriginalJson() { // return mOriginalJson; // } // // /** // * @return the signature, as received from the billing service. // */ // public String getSignature() { return mSignature; } // // @Override // public String toString() { // return "Purchase(type:" + mItemType + "):" + mOriginalJson; // } // // /** // * The purchase state of the order. // */ // public enum State { // PURCHASED(0), // CANCELED(1), // REFUNDED(2), // UNKNOWN(-1); // // final int code; // // State(int code) { // this.code = code; // } // public static State fromCode(int code) { // for (State s : values()) { // if (s.code == code) return s; // } // return UNKNOWN; // } // } // // // fields used in service JSON response // private static final String PACKAGE_NAME = "packageName"; // private static final String PRODUCT_ID = "productId"; // private static final String PURCHASE_TIME = "purchaseTime"; // private static final String PURCHASE_STATE = "purchaseState"; // private static final String DEVELOPER_PAYLOAD = "developerPayload"; // private static final String PURCHASE_TOKEN = "purchaseToken"; // private static final String TOKEN = "token"; // private static final String ORDER_ID = "orderId"; // }
import com.github.jberkel.pay.me.listener.OnIabPurchaseFinishedListener; import com.github.jberkel.pay.me.model.ItemType; import com.github.jberkel.pay.me.model.Purchase; import static com.github.jberkel.pay.me.model.ItemType.UNKNOWN;
package com.github.jberkel.pay.me; class PurchaseFlowState implements OnIabPurchaseFinishedListener { static final PurchaseFlowState NONE = new PurchaseFlowState(-1, UNKNOWN, null); /** The request code used to launch purchase flow */ final int requestCode; /** The item type of the current purchase flow */
// Path: payme/src/main/java/main/java/com/github/jberkel/pay/me/model/ItemType.java // public enum ItemType { // /** normal in app purchase */ // INAPP, // /** subscription */ // SUBS, // /** unknown type */ // UNKNOWN; // // public String toString() { // return name().toLowerCase(Locale.ENGLISH); // } // // public static ItemType fromString(String type) { // for (ItemType t : values()) { // if (t.toString().equals(type)) return t; // } // return UNKNOWN; // } // } // // Path: payme/src/main/java/main/java/com/github/jberkel/pay/me/model/Purchase.java // public class Purchase { // // private final String mOrderId; // private final String mPackageName; // private final String mSku; // private final long mPurchaseTime; // private final int mPurchaseState; // private final String mDeveloperPayload; // private final String mToken; // // private final ItemType mItemType; // private final State mState; // private final String mSignature; // private final String mOriginalJson; // // // /** // * @param itemType the item type for this purchase, cannot be null. // * @param jsonPurchaseInfo the JSON representation of this purchase // * @param signature the signature // * @throws JSONException if the purchase cannot be parsed or is invalid. // */ // public Purchase(ItemType itemType, String jsonPurchaseInfo, String signature) throws JSONException { // if (itemType == null) throw new IllegalArgumentException("itemType cannot be null"); // mItemType = itemType; // final JSONObject json = new JSONObject(jsonPurchaseInfo); // // mOrderId = json.optString(ORDER_ID); // mPackageName = json.optString(PACKAGE_NAME); // mSku = json.optString(PRODUCT_ID); // mPurchaseTime = json.optLong(PURCHASE_TIME); // mPurchaseState = json.optInt(PURCHASE_STATE); // mDeveloperPayload = json.optString(DEVELOPER_PAYLOAD); // mToken = json.optString(TOKEN, json.optString(PURCHASE_TOKEN)); // // mOriginalJson = jsonPurchaseInfo; // mSignature = signature; // mState = State.fromCode(mPurchaseState); // // if (TextUtils.isEmpty(mSku)) { // throw new JSONException("SKU is empty"); // } // } // // public ItemType getItemType() { // return mItemType; // } // // /** // * @return A unique order identifier for the transaction. This corresponds to the Google Wallet Order ID. // */ // public String getOrderId() { // return mOrderId; // } // // /** // * // * @return The application package from which the purchase originated. // */ // public String getPackageName() { // return mPackageName; // } // // /** // * @return The item's product identifier. Every item has a product ID, which you must specify in // * the application's product list on the Google Play Developer Console. // */ // public String getSku() { // return mSku; // } // // /** // * @return The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970). // */ // public long getPurchaseTime() { // return mPurchaseTime; // } // // /** // * @return The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded). // */ // public int getRawState() { // return mPurchaseState; // } // // /** // * @return The parsed purchase state of the order. // */ // public State getState() { // return mState; // } // // /** // * @return A developer-specified string that contains supplemental information about an order. You // * can specify a value for this field when you make a getBuyIntent request. // */ // public String getDeveloperPayload() { // return mDeveloperPayload; // } // // /** // * @return A token that uniquely identifies a purchase for a given item and user pair. // */ // public String getToken() { // return mToken; // } // // /** // * @return the original JSON response, as received from the billing service. // */ // public String getOriginalJson() { // return mOriginalJson; // } // // /** // * @return the signature, as received from the billing service. // */ // public String getSignature() { return mSignature; } // // @Override // public String toString() { // return "Purchase(type:" + mItemType + "):" + mOriginalJson; // } // // /** // * The purchase state of the order. // */ // public enum State { // PURCHASED(0), // CANCELED(1), // REFUNDED(2), // UNKNOWN(-1); // // final int code; // // State(int code) { // this.code = code; // } // public static State fromCode(int code) { // for (State s : values()) { // if (s.code == code) return s; // } // return UNKNOWN; // } // } // // // fields used in service JSON response // private static final String PACKAGE_NAME = "packageName"; // private static final String PRODUCT_ID = "productId"; // private static final String PURCHASE_TIME = "purchaseTime"; // private static final String PURCHASE_STATE = "purchaseState"; // private static final String DEVELOPER_PAYLOAD = "developerPayload"; // private static final String PURCHASE_TOKEN = "purchaseToken"; // private static final String TOKEN = "token"; // private static final String ORDER_ID = "orderId"; // } // Path: payme/src/main/java/main/java/com/github/jberkel/pay/me/PurchaseFlowState.java import com.github.jberkel.pay.me.listener.OnIabPurchaseFinishedListener; import com.github.jberkel.pay.me.model.ItemType; import com.github.jberkel.pay.me.model.Purchase; import static com.github.jberkel.pay.me.model.ItemType.UNKNOWN; package com.github.jberkel.pay.me; class PurchaseFlowState implements OnIabPurchaseFinishedListener { static final PurchaseFlowState NONE = new PurchaseFlowState(-1, UNKNOWN, null); /** The request code used to launch purchase flow */ final int requestCode; /** The item type of the current purchase flow */
final ItemType itemType;
damnhandy/Handy-URI-Templates
src/test/java/com/damnhandy/uri/template/impl/TestUriTemplateParser.java
// Path: src/main/java/com/damnhandy/uri/template/MalformedUriTemplateException.java // public class MalformedUriTemplateException extends RuntimeException // { // // /** The serialVersionUID */ // private static final long serialVersionUID = 5883174281977078450L; // // private final int location; // /** // * Create a new UriTemplateParseException. // * // * @param message // * @param cause // */ // public MalformedUriTemplateException(String message, final int location, Throwable cause) // { // super(message, cause); // this.location = location; // } // // /** // * Create a new UriTemplateParseException. // * // * @param message // */ // public MalformedUriTemplateException(String message, int location) // { // super(message); // this.location = location; // } // // public int getLocation() // { // return this.location; // } // }
import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.Assert; import org.junit.Test; import com.damnhandy.uri.template.MalformedUriTemplateException; import com.damnhandy.uri.template.UriTemplateComponent;
{ String template = "http://example.com/{expr}/thing/{other}"; UriTemplateParser e = new UriTemplateParser(); List<UriTemplateComponent> expressions = e.scan(template); List<String> regExExpr = scanWithRegEx(template); Assert.assertEquals(4, expressions.size()); Assert.assertEquals("http://example.com/", expressions.get(0).getValue()); Assert.assertEquals(regExExpr.get(0), expressions.get(1).getValue()); Assert.assertEquals("/thing/", expressions.get(2).getValue()); Assert.assertEquals(regExExpr.get(1), expressions.get(3).getValue()); } @Test public void testGoodTemplateWithOperators() throws Exception { UriTemplateParser e = new UriTemplateParser(); List<UriTemplateComponent> expressions = e.scan("http://example.com/{expr}/thing/{?other,thing}"); Assert.assertEquals(4, expressions.size()); Assert.assertEquals("http://example.com/", expressions.get(0).getValue()); Assert.assertEquals("{expr}", expressions.get(1).getValue()); Assert.assertEquals("/thing/", expressions.get(2).getValue()); Assert.assertEquals("{?other,thing}", expressions.get(3).getValue()); } /** * Checking that we correctly catch an unbalanced expression * * @throws Exception */
// Path: src/main/java/com/damnhandy/uri/template/MalformedUriTemplateException.java // public class MalformedUriTemplateException extends RuntimeException // { // // /** The serialVersionUID */ // private static final long serialVersionUID = 5883174281977078450L; // // private final int location; // /** // * Create a new UriTemplateParseException. // * // * @param message // * @param cause // */ // public MalformedUriTemplateException(String message, final int location, Throwable cause) // { // super(message, cause); // this.location = location; // } // // /** // * Create a new UriTemplateParseException. // * // * @param message // */ // public MalformedUriTemplateException(String message, int location) // { // super(message); // this.location = location; // } // // public int getLocation() // { // return this.location; // } // } // Path: src/test/java/com/damnhandy/uri/template/impl/TestUriTemplateParser.java import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.Assert; import org.junit.Test; import com.damnhandy.uri.template.MalformedUriTemplateException; import com.damnhandy.uri.template.UriTemplateComponent; { String template = "http://example.com/{expr}/thing/{other}"; UriTemplateParser e = new UriTemplateParser(); List<UriTemplateComponent> expressions = e.scan(template); List<String> regExExpr = scanWithRegEx(template); Assert.assertEquals(4, expressions.size()); Assert.assertEquals("http://example.com/", expressions.get(0).getValue()); Assert.assertEquals(regExExpr.get(0), expressions.get(1).getValue()); Assert.assertEquals("/thing/", expressions.get(2).getValue()); Assert.assertEquals(regExExpr.get(1), expressions.get(3).getValue()); } @Test public void testGoodTemplateWithOperators() throws Exception { UriTemplateParser e = new UriTemplateParser(); List<UriTemplateComponent> expressions = e.scan("http://example.com/{expr}/thing/{?other,thing}"); Assert.assertEquals(4, expressions.size()); Assert.assertEquals("http://example.com/", expressions.get(0).getValue()); Assert.assertEquals("{expr}", expressions.get(1).getValue()); Assert.assertEquals("/thing/", expressions.get(2).getValue()); Assert.assertEquals("{?other,thing}", expressions.get(3).getValue()); } /** * Checking that we correctly catch an unbalanced expression * * @throws Exception */
@Test(expected = MalformedUriTemplateException.class)
damnhandy/Handy-URI-Templates
src/main/java/com/damnhandy/uri/template/impl/VarSpec.java
// Path: src/main/java/com/damnhandy/uri/template/MalformedUriTemplateException.java // public class MalformedUriTemplateException extends RuntimeException // { // // /** The serialVersionUID */ // private static final long serialVersionUID = 5883174281977078450L; // // private final int location; // /** // * Create a new UriTemplateParseException. // * // * @param message // * @param cause // */ // public MalformedUriTemplateException(String message, final int location, Throwable cause) // { // super(message, cause); // this.location = location; // } // // /** // * Create a new UriTemplateParseException. // * // * @param message // */ // public MalformedUriTemplateException(String message, int location) // { // super(message); // this.location = location; // } // // public int getLocation() // { // return this.location; // } // }
import com.damnhandy.uri.template.MalformedUriTemplateException; import java.io.Serializable; import java.util.regex.Matcher; import java.util.regex.Pattern;
variableName = getValue(); if (modifier != Modifier.NONE) { if (modifier == Modifier.PREFIX) { String[] values = getValue().split(Modifier.PREFIX.getValue()); variableName = values[0]; } // Strip the '*' from the variable name if it's presnet on the variable // name. Note that in the case of the UriTemplateBuilder, the VarSpec // is not responsible for rendering the '*' on the generated template // output as that is done in the UriTemplateBuilder if (modifier == Modifier.EXPLODE && getValue().lastIndexOf('*') != -1) { variableName = getValue().substring(0, getValue().length() - 1); } } // Double check if the name has an explode modifier. This could happen // using one of the template builder APIs. If the ends with '*' // strip it and set the modifier to EXPLODE else if (variableName.lastIndexOf('*') != -1) { variableName = getValue().substring(0, getValue().length() - 1); modifier = Modifier.EXPLODE; } // Validation needs to happen after strip out the modifier or prefix Matcher matcher = VARNAME_REGEX.matcher(variableName); if (!matcher.matches()) {
// Path: src/main/java/com/damnhandy/uri/template/MalformedUriTemplateException.java // public class MalformedUriTemplateException extends RuntimeException // { // // /** The serialVersionUID */ // private static final long serialVersionUID = 5883174281977078450L; // // private final int location; // /** // * Create a new UriTemplateParseException. // * // * @param message // * @param cause // */ // public MalformedUriTemplateException(String message, final int location, Throwable cause) // { // super(message, cause); // this.location = location; // } // // /** // * Create a new UriTemplateParseException. // * // * @param message // */ // public MalformedUriTemplateException(String message, int location) // { // super(message); // this.location = location; // } // // public int getLocation() // { // return this.location; // } // } // Path: src/main/java/com/damnhandy/uri/template/impl/VarSpec.java import com.damnhandy.uri.template.MalformedUriTemplateException; import java.io.Serializable; import java.util.regex.Matcher; import java.util.regex.Pattern; variableName = getValue(); if (modifier != Modifier.NONE) { if (modifier == Modifier.PREFIX) { String[] values = getValue().split(Modifier.PREFIX.getValue()); variableName = values[0]; } // Strip the '*' from the variable name if it's presnet on the variable // name. Note that in the case of the UriTemplateBuilder, the VarSpec // is not responsible for rendering the '*' on the generated template // output as that is done in the UriTemplateBuilder if (modifier == Modifier.EXPLODE && getValue().lastIndexOf('*') != -1) { variableName = getValue().substring(0, getValue().length() - 1); } } // Double check if the name has an explode modifier. This could happen // using one of the template builder APIs. If the ends with '*' // strip it and set the modifier to EXPLODE else if (variableName.lastIndexOf('*') != -1) { variableName = getValue().substring(0, getValue().length() - 1); modifier = Modifier.EXPLODE; } // Validation needs to happen after strip out the modifier or prefix Matcher matcher = VARNAME_REGEX.matcher(variableName); if (!matcher.matches()) {
throw new MalformedUriTemplateException("The variable name " + variableName + " contains invalid characters", position);
damnhandy/Handy-URI-Templates
src/test/java/com/damnhandy/uri/template/TestUriTemplateBuilder.java
// Path: src/main/java/com/damnhandy/uri/template/UriTemplateBuilder.java // public static VarSpec var(String varName) // { // return var(varName, Modifier.NONE, null); // }
import org.junit.Assert; import org.junit.Test; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import static com.damnhandy.uri.template.UriTemplateBuilder.var;
/* * Copyright 2012, Ryan J. McDonough * * 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. */ package com.damnhandy.uri.template; /** * A TestUriTemplateBuilder. * * @author <a href="ryan@damnhandy.com">Ryan J. McDonough</a> * @version $Revision: 1.1 $ */ public class TestUriTemplateBuilder { private static final String VAR_NAME = "foo"; private static final String BASE_URI = "http://example.com/"; @Test public void testCreateBasicTemplate() throws Exception { UriTemplate template = UriTemplate.buildFromTemplate("http://example.com") .literal("/foo")
// Path: src/main/java/com/damnhandy/uri/template/UriTemplateBuilder.java // public static VarSpec var(String varName) // { // return var(varName, Modifier.NONE, null); // } // Path: src/test/java/com/damnhandy/uri/template/TestUriTemplateBuilder.java import org.junit.Assert; import org.junit.Test; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import static com.damnhandy.uri.template.UriTemplateBuilder.var; /* * Copyright 2012, Ryan J. McDonough * * 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. */ package com.damnhandy.uri.template; /** * A TestUriTemplateBuilder. * * @author <a href="ryan@damnhandy.com">Ryan J. McDonough</a> * @version $Revision: 1.1 $ */ public class TestUriTemplateBuilder { private static final String VAR_NAME = "foo"; private static final String BASE_URI = "http://example.com/"; @Test public void testCreateBasicTemplate() throws Exception { UriTemplate template = UriTemplate.buildFromTemplate("http://example.com") .literal("/foo")
.path(var("thing1"), var("explodedThing", true))
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override
public Status reloadStatus() {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() {
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() {
return StatusRandomizer.random();
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override
public Resource getResource() {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override public Resource getResource() {
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { public CoreApiServiceStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override public Resource getResource() {
return new ResourceImpl("API service", "Core API service of web site");
YagelNasManit/environment.monitor
environment.monitor.plugins/src/test/java/org/yagel/monitor/plugins/TestMonitorConfigReader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // }
import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.MonitorConfig;
package org.yagel.monitor.plugins; public class TestMonitorConfigReader { @Test void testMonitorConfigDeserialization() { String mockConfig = getClass().getClassLoader().getResource("Environment-Mock.xml").toString();
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // Path: environment.monitor.plugins/src/test/java/org/yagel/monitor/plugins/TestMonitorConfigReader.java import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.MonitorConfig; package org.yagel.monitor.plugins; public class TestMonitorConfigReader { @Test void testMonitorConfigDeserialization() { String mockConfig = getClass().getClassLoader().getResource("Environment-Mock.xml").toString();
MonitorConfig config = new MonitorConfigReader().readMonitorConfig(mockConfig);
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/unit/DataUtilsTest.java
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/utils/DataUtils.java // public class DataUtils { // // /** // * @param date // * @return aggregated year and month values of given date field. Month is counted from 0 // * <p/> // * For example: // * If date is 2015-02-03 then return value will be 201501 // */ // public static int joinYearMonthValues(Date date) { // Calendar calendar = DateUtils.toCalendar(date); // return joinYearMonthValues(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)); // } // // public static int joinYearMonthValues(int year, int month) { // return year * 100 + month; // } // // public static Date getYesterday(Date currentDate) { // return DateUtils.addDays(currentDate, -1); // } // // public static boolean isToday(LocalDateTime localDateTime) { // return localDateTime.getDayOfYear() == LocalDateTime.now().getDayOfYear(); // } // // public static Date asDate(LocalDate localDate) { // return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); // } // // public static Date asDate(LocalDateTime localDateTime) { // return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); // } // // public static LocalDate asLocalDate(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate(); // } // // public static LocalDateTime asLocalDateTime(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); // } // // public static List<Integer> getMonthNumbersInDateFrame(Date startDate, Date endDate) { // List<Integer> dates = new ArrayList<>(); // // LocalDateTime start = asLocalDateTime(startDate); // LocalDateTime end = asLocalDateTime(endDate); // // // while (start.isBefore(end) || start.equals(end)) { // dates.add(start.getMonthValue()); // start = start.plusMonths(1); // } // return dates; // // } // // public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException { // // List<Date[]> dates = new ArrayList<>(); // // LocalDateTime dFrom = asLocalDateTime(from); // LocalDateTime dTo = asLocalDateTime(to); // // if (dFrom.compareTo(dTo) >= 0) { // throw new IllegalArgumentException("Provide a to-date greater than the from-date"); // } // // while (dFrom.compareTo(dTo) < 0) { // // check if current time frame is last // boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear(); // // // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date // int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); // LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX; // // // // build timeframe // Date[] dar = new Date[2]; // dar[0] = asDate(dFrom); // dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time)); // // // add current timeframe // dates.add(dar); // // // jump to beginning of next month // dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay(); // } // // return dates; // // } // // // }
import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.utils.DataUtils; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Arrays; import java.util.Date; import java.util.List;
package org.yagel.monitor.runner.test.unit; public class DataUtilsTest { @Test public void testJoinYearAndMonthFirstMonthOfYear() throws Exception { LocalDate localDateTime = LocalDate.of(2017, 1, 1);
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/utils/DataUtils.java // public class DataUtils { // // /** // * @param date // * @return aggregated year and month values of given date field. Month is counted from 0 // * <p/> // * For example: // * If date is 2015-02-03 then return value will be 201501 // */ // public static int joinYearMonthValues(Date date) { // Calendar calendar = DateUtils.toCalendar(date); // return joinYearMonthValues(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)); // } // // public static int joinYearMonthValues(int year, int month) { // return year * 100 + month; // } // // public static Date getYesterday(Date currentDate) { // return DateUtils.addDays(currentDate, -1); // } // // public static boolean isToday(LocalDateTime localDateTime) { // return localDateTime.getDayOfYear() == LocalDateTime.now().getDayOfYear(); // } // // public static Date asDate(LocalDate localDate) { // return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); // } // // public static Date asDate(LocalDateTime localDateTime) { // return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); // } // // public static LocalDate asLocalDate(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate(); // } // // public static LocalDateTime asLocalDateTime(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); // } // // public static List<Integer> getMonthNumbersInDateFrame(Date startDate, Date endDate) { // List<Integer> dates = new ArrayList<>(); // // LocalDateTime start = asLocalDateTime(startDate); // LocalDateTime end = asLocalDateTime(endDate); // // // while (start.isBefore(end) || start.equals(end)) { // dates.add(start.getMonthValue()); // start = start.plusMonths(1); // } // return dates; // // } // // public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException { // // List<Date[]> dates = new ArrayList<>(); // // LocalDateTime dFrom = asLocalDateTime(from); // LocalDateTime dTo = asLocalDateTime(to); // // if (dFrom.compareTo(dTo) >= 0) { // throw new IllegalArgumentException("Provide a to-date greater than the from-date"); // } // // while (dFrom.compareTo(dTo) < 0) { // // check if current time frame is last // boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear(); // // // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date // int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); // LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX; // // // // build timeframe // Date[] dar = new Date[2]; // dar[0] = asDate(dFrom); // dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time)); // // // add current timeframe // dates.add(dar); // // // jump to beginning of next month // dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay(); // } // // return dates; // // } // // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/unit/DataUtilsTest.java import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.utils.DataUtils; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Arrays; import java.util.Date; import java.util.List; package org.yagel.monitor.runner.test.unit; public class DataUtilsTest { @Test public void testJoinYearAndMonthFirstMonthOfYear() throws Exception { LocalDate localDateTime = LocalDate.of(2017, 1, 1);
int joinedYearAndMonth = DataUtils.joinYearMonthValues(DataUtils.asDate(localDateTime));
YagelNasManit/environment.monitor
environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // }
import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorConfig; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement;
package org.yagel.monitor.config; @XmlRootElement(name = "monitorConfig") @XmlAccessorType(XmlAccessType.FIELD)
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorConfig; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; package org.yagel.monitor.config; @XmlRootElement(name = "monitorConfig") @XmlAccessorType(XmlAccessType.FIELD)
public class MonitorConfigImpl implements MonitorConfig {
YagelNasManit/environment.monitor
environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // }
import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorConfig; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement;
package org.yagel.monitor.config; @XmlRootElement(name = "monitorConfig") @XmlAccessorType(XmlAccessType.FIELD) public class MonitorConfigImpl implements MonitorConfig { private static MonitorConfig config; @XmlElement(type = EnvironmentConfigImpl.class)
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorConfig; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; package org.yagel.monitor.config; @XmlRootElement(name = "monitorConfig") @XmlAccessorType(XmlAccessType.FIELD) public class MonitorConfigImpl implements MonitorConfig { private static MonitorConfig config; @XmlElement(type = EnvironmentConfigImpl.class)
private Set<EnvironmentConfig> environments;
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceDAO.java
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/DocumentMapper.java // public static Document resourceToDocument(Resource resource) { // return new Document("_id", resource.getId()).append("name", resource.getName()); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // }
import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.in; import static org.yagel.monitor.mongo.DocumentMapper.resourceToDocument; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.UpdateOptions; import org.bson.Document; import org.yagel.monitor.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors;
package org.yagel.monitor.mongo; public class ResourceDAO extends AbstractDAO { private final static String COLLECTION_NAME = "Resources"; private MongoCollection<Document> thisCollection; public ResourceDAO(MongoDatabase db) { super(db); thisCollection = db.getCollection(COLLECTION_NAME); } /** * Inserts new resource to DB, or else updates existing resource description if existing ID was used * * @param resource resource to be upserted */
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/DocumentMapper.java // public static Document resourceToDocument(Resource resource) { // return new Document("_id", resource.getId()).append("name", resource.getName()); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceDAO.java import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.in; import static org.yagel.monitor.mongo.DocumentMapper.resourceToDocument; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.UpdateOptions; import org.bson.Document; import org.yagel.monitor.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; package org.yagel.monitor.mongo; public class ResourceDAO extends AbstractDAO { private final static String COLLECTION_NAME = "Resources"; private MongoCollection<Document> thisCollection; public ResourceDAO(MongoDatabase db) { super(db); thisCollection = db.getCollection(COLLECTION_NAME); } /** * Inserts new resource to DB, or else updates existing resource description if existing ID was used * * @param resource resource to be upserted */
public synchronized void insert(Resource resource) {
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceDAO.java
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/DocumentMapper.java // public static Document resourceToDocument(Resource resource) { // return new Document("_id", resource.getId()).append("name", resource.getName()); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // }
import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.in; import static org.yagel.monitor.mongo.DocumentMapper.resourceToDocument; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.UpdateOptions; import org.bson.Document; import org.yagel.monitor.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors;
package org.yagel.monitor.mongo; public class ResourceDAO extends AbstractDAO { private final static String COLLECTION_NAME = "Resources"; private MongoCollection<Document> thisCollection; public ResourceDAO(MongoDatabase db) { super(db); thisCollection = db.getCollection(COLLECTION_NAME); } /** * Inserts new resource to DB, or else updates existing resource description if existing ID was used * * @param resource resource to be upserted */ public synchronized void insert(Resource resource) { this.thisCollection.replaceOne( eq("_id", resource.getId()),
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/DocumentMapper.java // public static Document resourceToDocument(Resource resource) { // return new Document("_id", resource.getId()).append("name", resource.getName()); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceDAO.java import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.in; import static org.yagel.monitor.mongo.DocumentMapper.resourceToDocument; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.UpdateOptions; import org.bson.Document; import org.yagel.monitor.Resource; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; package org.yagel.monitor.mongo; public class ResourceDAO extends AbstractDAO { private final static String COLLECTION_NAME = "Resources"; private MongoCollection<Document> thisCollection; public ResourceDAO(MongoDatabase db) { super(db); thisCollection = db.getCollection(COLLECTION_NAME); } /** * Inserts new resource to DB, or else updates existing resource description if existing ID was used * * @param resource resource to be upserted */ public synchronized void insert(Resource resource) { this.thisCollection.replaceOne( eq("_id", resource.getId()),
resourceToDocument(resource),
YagelNasManit/environment.monitor
environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatusProvider.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.monitor.resource.Status;
package org.yagel.monitor; public interface ResourceStatusProvider { String getName();
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatusProvider.java import org.yagel.monitor.resource.Status; package org.yagel.monitor; public interface ResourceStatusProvider { String getName();
Status reloadStatus();
YagelNasManit/environment.monitor
environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/dto/EnvironmentConfigDTO.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // }
import org.yagel.monitor.Resource; import java.util.Set;
package org.yagel.monitor.api.rest.dto; public class EnvironmentConfigDTO { private String environmentName;
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // Path: environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/dto/EnvironmentConfigDTO.java import org.yagel.monitor.Resource; import java.util.Set; package org.yagel.monitor.api.rest.dto; public class EnvironmentConfigDTO { private String environmentName;
private Set<Resource> checkedResources;
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceStatusDetailDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceStatusDetailDAO.java // public class ResourceStatusDetailDAO extends AbstractTimeRangeDAO { // // public ResourceStatusDetailDAO(MongoDatabase mongoDatabase) { // super(mongoDatabase); // switchCollection(new Date()); // } // // // /** // * Inserts new resource status into corresponding month collection // * // * @param environmentName environment resource belongs to // * @param resourceStatus status to be inserted // */ // public synchronized void insert(String environmentName, ResourceStatus resourceStatus) { // switchCollection(resourceStatus.getUpdated()); // thisCollection.insertOne(resourceStatusToDocument(environmentName, resourceStatus)); // } // // // /** // * Inserts multiple resource statuses into corresponding month collection // * @param environmentName // * @param resourcesStatus // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resourcesStatus) { // resourcesStatus.forEach(rs -> { // switchCollection(rs.getUpdated()); // insert(environmentName, rs); // }); // } // // // @Deprecated // public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) { // // consider month switch during data extraction if will be used // switchCollection(from); // // return thisCollection.find(and( // eq("environmentName", environmentName), // gte("updated", from), // lte("updated", to), // eq("resource.resourceId", resourceId)) // ) // .sort(Sorts.ascending("updated")) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // } // // /** // * Fetch time scale statuses for particular resource // * @param environmentName environment that resource belongs to // * @param resourceId resource id to fetch statuses // * @param from start date for statuses fetching // * @param to end date for statuses fetching // * @return // */ // public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) { // List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to); // List<StatusUpdate> updates = new ArrayList<>(); // // for (Date[] dates : dateFrames) { // switchCollection(dates[0]); // // Bson filter = and( // eq("environmentName", environmentName), // eq("resource.resourceId", resourceId), // gte("updated", dates[0]), // lte("updated", dates[1]) // ); // // Bson project = fields(include("updated", "statusOrdinal"), excludeId()); // // List<StatusUpdate> monthlyUpdates = this.thisCollection // .find(filter) // .projection(project) // .map( // doc -> new StatusUpdateImpl( // Status.fromSerialNumber(doc.getInteger("statusOrdinal")), // doc.getDate("updated") // ) // ) // .into(new ArrayList<>()); // // updates.addAll(monthlyUpdates); // } // return updates; // // } // }
import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceStatusDetailDAO; import java.util.List; import java.util.UUID;
package org.yagel.monitor.runner.test.intergation.dao; public class ResourceStatusDetailDAOTest extends AbstractDAOTest { private ResourceStatusDetailDAO monthDetailDAO; private String environemntName; @BeforeClass public void setUp() throws Exception {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceStatusDetailDAO.java // public class ResourceStatusDetailDAO extends AbstractTimeRangeDAO { // // public ResourceStatusDetailDAO(MongoDatabase mongoDatabase) { // super(mongoDatabase); // switchCollection(new Date()); // } // // // /** // * Inserts new resource status into corresponding month collection // * // * @param environmentName environment resource belongs to // * @param resourceStatus status to be inserted // */ // public synchronized void insert(String environmentName, ResourceStatus resourceStatus) { // switchCollection(resourceStatus.getUpdated()); // thisCollection.insertOne(resourceStatusToDocument(environmentName, resourceStatus)); // } // // // /** // * Inserts multiple resource statuses into corresponding month collection // * @param environmentName // * @param resourcesStatus // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resourcesStatus) { // resourcesStatus.forEach(rs -> { // switchCollection(rs.getUpdated()); // insert(environmentName, rs); // }); // } // // // @Deprecated // public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) { // // consider month switch during data extraction if will be used // switchCollection(from); // // return thisCollection.find(and( // eq("environmentName", environmentName), // gte("updated", from), // lte("updated", to), // eq("resource.resourceId", resourceId)) // ) // .sort(Sorts.ascending("updated")) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // } // // /** // * Fetch time scale statuses for particular resource // * @param environmentName environment that resource belongs to // * @param resourceId resource id to fetch statuses // * @param from start date for statuses fetching // * @param to end date for statuses fetching // * @return // */ // public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) { // List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to); // List<StatusUpdate> updates = new ArrayList<>(); // // for (Date[] dates : dateFrames) { // switchCollection(dates[0]); // // Bson filter = and( // eq("environmentName", environmentName), // eq("resource.resourceId", resourceId), // gte("updated", dates[0]), // lte("updated", dates[1]) // ); // // Bson project = fields(include("updated", "statusOrdinal"), excludeId()); // // List<StatusUpdate> monthlyUpdates = this.thisCollection // .find(filter) // .projection(project) // .map( // doc -> new StatusUpdateImpl( // Status.fromSerialNumber(doc.getInteger("statusOrdinal")), // doc.getDate("updated") // ) // ) // .into(new ArrayList<>()); // // updates.addAll(monthlyUpdates); // } // return updates; // // } // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceStatusDetailDAOTest.java import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceStatusDetailDAO; import java.util.List; import java.util.UUID; package org.yagel.monitor.runner.test.intergation.dao; public class ResourceStatusDetailDAOTest extends AbstractDAOTest { private ResourceStatusDetailDAO monthDetailDAO; private String environemntName; @BeforeClass public void setUp() throws Exception {
monthDetailDAO = MongoConnector.getInstance().getMonthDetailDAO();
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceStatusDetailDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceStatusDetailDAO.java // public class ResourceStatusDetailDAO extends AbstractTimeRangeDAO { // // public ResourceStatusDetailDAO(MongoDatabase mongoDatabase) { // super(mongoDatabase); // switchCollection(new Date()); // } // // // /** // * Inserts new resource status into corresponding month collection // * // * @param environmentName environment resource belongs to // * @param resourceStatus status to be inserted // */ // public synchronized void insert(String environmentName, ResourceStatus resourceStatus) { // switchCollection(resourceStatus.getUpdated()); // thisCollection.insertOne(resourceStatusToDocument(environmentName, resourceStatus)); // } // // // /** // * Inserts multiple resource statuses into corresponding month collection // * @param environmentName // * @param resourcesStatus // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resourcesStatus) { // resourcesStatus.forEach(rs -> { // switchCollection(rs.getUpdated()); // insert(environmentName, rs); // }); // } // // // @Deprecated // public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) { // // consider month switch during data extraction if will be used // switchCollection(from); // // return thisCollection.find(and( // eq("environmentName", environmentName), // gte("updated", from), // lte("updated", to), // eq("resource.resourceId", resourceId)) // ) // .sort(Sorts.ascending("updated")) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // } // // /** // * Fetch time scale statuses for particular resource // * @param environmentName environment that resource belongs to // * @param resourceId resource id to fetch statuses // * @param from start date for statuses fetching // * @param to end date for statuses fetching // * @return // */ // public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) { // List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to); // List<StatusUpdate> updates = new ArrayList<>(); // // for (Date[] dates : dateFrames) { // switchCollection(dates[0]); // // Bson filter = and( // eq("environmentName", environmentName), // eq("resource.resourceId", resourceId), // gte("updated", dates[0]), // lte("updated", dates[1]) // ); // // Bson project = fields(include("updated", "statusOrdinal"), excludeId()); // // List<StatusUpdate> monthlyUpdates = this.thisCollection // .find(filter) // .projection(project) // .map( // doc -> new StatusUpdateImpl( // Status.fromSerialNumber(doc.getInteger("statusOrdinal")), // doc.getDate("updated") // ) // ) // .into(new ArrayList<>()); // // updates.addAll(monthlyUpdates); // } // return updates; // // } // }
import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceStatusDetailDAO; import java.util.List; import java.util.UUID;
package org.yagel.monitor.runner.test.intergation.dao; public class ResourceStatusDetailDAOTest extends AbstractDAOTest { private ResourceStatusDetailDAO monthDetailDAO; private String environemntName; @BeforeClass public void setUp() throws Exception { monthDetailDAO = MongoConnector.getInstance().getMonthDetailDAO(); String baseEnvName = this.getClass().getName(); environemntName = baseEnvName + UUID.randomUUID(); } @Test public void testInsertFindSingle() throws Exception {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceStatusDetailDAO.java // public class ResourceStatusDetailDAO extends AbstractTimeRangeDAO { // // public ResourceStatusDetailDAO(MongoDatabase mongoDatabase) { // super(mongoDatabase); // switchCollection(new Date()); // } // // // /** // * Inserts new resource status into corresponding month collection // * // * @param environmentName environment resource belongs to // * @param resourceStatus status to be inserted // */ // public synchronized void insert(String environmentName, ResourceStatus resourceStatus) { // switchCollection(resourceStatus.getUpdated()); // thisCollection.insertOne(resourceStatusToDocument(environmentName, resourceStatus)); // } // // // /** // * Inserts multiple resource statuses into corresponding month collection // * @param environmentName // * @param resourcesStatus // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resourcesStatus) { // resourcesStatus.forEach(rs -> { // switchCollection(rs.getUpdated()); // insert(environmentName, rs); // }); // } // // // @Deprecated // public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) { // // consider month switch during data extraction if will be used // switchCollection(from); // // return thisCollection.find(and( // eq("environmentName", environmentName), // gte("updated", from), // lte("updated", to), // eq("resource.resourceId", resourceId)) // ) // .sort(Sorts.ascending("updated")) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // } // // /** // * Fetch time scale statuses for particular resource // * @param environmentName environment that resource belongs to // * @param resourceId resource id to fetch statuses // * @param from start date for statuses fetching // * @param to end date for statuses fetching // * @return // */ // public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) { // List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to); // List<StatusUpdate> updates = new ArrayList<>(); // // for (Date[] dates : dateFrames) { // switchCollection(dates[0]); // // Bson filter = and( // eq("environmentName", environmentName), // eq("resource.resourceId", resourceId), // gte("updated", dates[0]), // lte("updated", dates[1]) // ); // // Bson project = fields(include("updated", "statusOrdinal"), excludeId()); // // List<StatusUpdate> monthlyUpdates = this.thisCollection // .find(filter) // .projection(project) // .map( // doc -> new StatusUpdateImpl( // Status.fromSerialNumber(doc.getInteger("statusOrdinal")), // doc.getDate("updated") // ) // ) // .into(new ArrayList<>()); // // updates.addAll(monthlyUpdates); // } // return updates; // // } // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceStatusDetailDAOTest.java import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceStatusDetailDAO; import java.util.List; import java.util.UUID; package org.yagel.monitor.runner.test.intergation.dao; public class ResourceStatusDetailDAOTest extends AbstractDAOTest { private ResourceStatusDetailDAO monthDetailDAO; private String environemntName; @BeforeClass public void setUp() throws Exception { monthDetailDAO = MongoConnector.getInstance().getMonthDetailDAO(); String baseEnvName = this.getClass().getName(); environemntName = baseEnvName + UUID.randomUUID(); } @Test public void testInsertFindSingle() throws Exception {
ResourceStatus resourceStatus = rndResStatus(rndResource());
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/exception/DiagnosticException.java // public class DiagnosticException extends RuntimeException { // // // public DiagnosticException(Throwable cause) { // super(cause); // } // }
import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; import com.mongodb.client.MongoDatabase; import org.apache.log4j.Logger; import org.yagel.monitor.exception.DiagnosticException;
package org.yagel.monitor.mongo; public class MongoConnector { private final static String MONITOR_DB = "monitor_tmp_newDomain"; private final static Logger log = Logger.getLogger(MongoConnector.class); private static MongoConnector connector; private MongoDatabase db; private MongoClient client;
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/exception/DiagnosticException.java // public class DiagnosticException extends RuntimeException { // // // public DiagnosticException(Throwable cause) { // super(cause); // } // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java import com.mongodb.MongoClient; import com.mongodb.MongoClientURI; import com.mongodb.client.MongoDatabase; import org.apache.log4j.Logger; import org.yagel.monitor.exception.DiagnosticException; package org.yagel.monitor.mongo; public class MongoConnector { private final static String MONITOR_DB = "monitor_tmp_newDomain"; private final static Logger log = Logger.getLogger(MongoConnector.class); private static MongoConnector connector; private MongoDatabase db; private MongoClient client;
private MongoConnector() throws DiagnosticException {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override
public Status reloadStatus() {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() {
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() {
return StatusRandomizer.random();
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override
public Resource getResource() {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override public Resource getResource() {
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class DataBaseStatusProvider extends AbstractResourceStatusProvider { public DataBaseStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override public Resource getResource() {
return new ResourceImpl("DataBase", "Environment DataBase");
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller;
package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class);
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class);
MonitorConfig readMonitorConfig(String configUrl) {
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller;
package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class); MonitorConfig readMonitorConfig(String configUrl) { try { log.info("Loading configuration"); JAXBContext context;
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class); MonitorConfig readMonitorConfig(String configUrl) { try { log.info("Loading configuration"); JAXBContext context;
context = JAXBContext.newInstance(MonitorConfigImpl.class, EnvironmentConfigImpl.class);
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller;
package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class); MonitorConfig readMonitorConfig(String configUrl) { try { log.info("Loading configuration"); JAXBContext context;
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class); MonitorConfig readMonitorConfig(String configUrl) { try { log.info("Loading configuration"); JAXBContext context;
context = JAXBContext.newInstance(MonitorConfigImpl.class, EnvironmentConfigImpl.class);
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller;
package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class); MonitorConfig readMonitorConfig(String configUrl) { try { log.info("Loading configuration"); JAXBContext context; context = JAXBContext.newInstance(MonitorConfigImpl.class, EnvironmentConfigImpl.class); Unmarshaller um = context.createUnmarshaller(); MonitorConfig config = (MonitorConfig) um.unmarshal(new URL(configUrl)); log.info("Loading configuration - done."); return config; } catch (JAXBException | MalformedURLException e) { log.error("Error during configuration deserialization s" + e.getMessage());
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java // @XmlRootElement // @XmlAccessorType(XmlAccessType.FIELD) // public class EnvironmentConfigImpl implements EnvironmentConfig { // // private String evnName; // private long taskDelay; // private String host; // private int appVersion; // @XmlElementWrapper(name = "checkedResources") // @XmlElement(name = "resource") // private Set<String> checkedResources; // private Map<String, String> additionalProperties; // // // @Override // public String getEnvName() { // return this.evnName; // } // // @Override // public String getHost() { // return this.host; // } // // @Override // public long getTaskDelay() { // return taskDelay; // } // // @Override // public int getAppVersion() { // return appVersion; // } // // // @Override // public Set<String> getCheckResources() { // return this.checkedResources; // } // // @Override // public Map<String, String> getAdditionalProperties() { // return this.additionalProperties; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/MonitorConfigImpl.java // @XmlRootElement(name = "monitorConfig") // @XmlAccessorType(XmlAccessType.FIELD) // public class MonitorConfigImpl implements MonitorConfig { // // private static MonitorConfig config; // // @XmlElement(type = EnvironmentConfigImpl.class) // private Set<EnvironmentConfig> environments; // // @XmlElement // private String pluginCollectorLocation; // // @Override // public Set<EnvironmentConfig> getEnvironments() { // return environments; // } // // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/MonitorConfigDeserializationException.java // public class MonitorConfigDeserializationException extends RuntimeException { // // public MonitorConfigDeserializationException(Throwable cause) { // super(cause); // } // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/MonitorConfigReader.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.config.EnvironmentConfigImpl; import org.yagel.monitor.config.MonitorConfigImpl; import org.yagel.monitor.plugins.exception.MonitorConfigDeserializationException; import java.net.MalformedURLException; import java.net.URL; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; package org.yagel.monitor.plugins; class MonitorConfigReader { private final static Logger log = Logger.getLogger(MonitorConfigReader.class); MonitorConfig readMonitorConfig(String configUrl) { try { log.info("Loading configuration"); JAXBContext context; context = JAXBContext.newInstance(MonitorConfigImpl.class, EnvironmentConfigImpl.class); Unmarshaller um = context.createUnmarshaller(); MonitorConfig config = (MonitorConfig) um.unmarshal(new URL(configUrl)); log.info("Loading configuration - done."); return config; } catch (JAXBException | MalformedURLException e) { log.error("Error during configuration deserialization s" + e.getMessage());
throw new MonitorConfigDeserializationException(e);
YagelNasManit/environment.monitor
environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // }
import org.yagel.monitor.EnvironmentConfig; import java.util.Map; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement;
package org.yagel.monitor.config; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD)
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // Path: environment.monitor.core/src/main/java/org/yagel/monitor/config/EnvironmentConfigImpl.java import org.yagel.monitor.EnvironmentConfig; import java.util.Map; import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; package org.yagel.monitor.config; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD)
public class EnvironmentConfigImpl implements EnvironmentConfig {
YagelNasManit/environment.monitor
environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/ResourceStatusService.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/StatusUpdate.java // public interface StatusUpdate { // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // }
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.yagel.monitor.StatusUpdate; import org.yagel.monitor.mongo.MongoConnector; import java.util.Date; import java.util.List;
package org.yagel.monitor.api.rest; @RestController @RequestMapping("/resource/status/") public class ResourceStatusService extends AbstractService { @RequestMapping(value = "{environmentName}/{resourceId}", method = RequestMethod.GET)
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/StatusUpdate.java // public interface StatusUpdate { // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // Path: environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/ResourceStatusService.java import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.yagel.monitor.StatusUpdate; import org.yagel.monitor.mongo.MongoConnector; import java.util.Date; import java.util.List; package org.yagel.monitor.api.rest; @RestController @RequestMapping("/resource/status/") public class ResourceStatusService extends AbstractService { @RequestMapping(value = "{environmentName}/{resourceId}", method = RequestMethod.GET)
public ResponseEntity<List<StatusUpdate>> getResourceStatuses(
YagelNasManit/environment.monitor
environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/ResourceStatusService.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/StatusUpdate.java // public interface StatusUpdate { // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // }
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.yagel.monitor.StatusUpdate; import org.yagel.monitor.mongo.MongoConnector; import java.util.Date; import java.util.List;
package org.yagel.monitor.api.rest; @RestController @RequestMapping("/resource/status/") public class ResourceStatusService extends AbstractService { @RequestMapping(value = "{environmentName}/{resourceId}", method = RequestMethod.GET) public ResponseEntity<List<StatusUpdate>> getResourceStatuses( @PathVariable("environmentName") String environmentName, @PathVariable(value = "resourceId") String resourceId, @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate, @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate) {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/StatusUpdate.java // public interface StatusUpdate { // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // Path: environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/ResourceStatusService.java import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.yagel.monitor.StatusUpdate; import org.yagel.monitor.mongo.MongoConnector; import java.util.Date; import java.util.List; package org.yagel.monitor.api.rest; @RestController @RequestMapping("/resource/status/") public class ResourceStatusService extends AbstractService { @RequestMapping(value = "{environmentName}/{resourceId}", method = RequestMethod.GET) public ResponseEntity<List<StatusUpdate>> getResourceStatuses( @PathVariable("environmentName") String environmentName, @PathVariable(value = "resourceId") String resourceId, @RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate, @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate) {
List<StatusUpdate> updateList = MongoConnector.getInstance().getMonthDetailDAO().getStatusUpdates(environmentName, resourceId, startDate, endDate);
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/AbstractResourceStatusProvider.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatusProvider.java // public interface ResourceStatusProvider { // // String getName(); // // Status reloadStatus(); // // Resource getResource(); // // // }
import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatusProvider;
package org.yagel.environment.monitor.test.extension.provider; public abstract class AbstractResourceStatusProvider implements ResourceStatusProvider { protected Resource resource;
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatusProvider.java // public interface ResourceStatusProvider { // // String getName(); // // Status reloadStatus(); // // Resource getResource(); // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/AbstractResourceStatusProvider.java import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatusProvider; package org.yagel.environment.monitor.test.extension.provider; public abstract class AbstractResourceStatusProvider implements ResourceStatusProvider { protected Resource resource;
protected EnvironmentConfig config;
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceLastStatusDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java // public class ResourceLastStatusDAO extends AbstractDAO { // // private final static String COLLECTION_NAME = "ResourceLastStatus"; // private MongoCollection<Document> thisCollection; // // // public ResourceLastStatusDAO(MongoDatabase db) { // super(db); // thisCollection = db.getCollection(COLLECTION_NAME); // } // // // /** // * Remove all last statuses for particular environment // * @param environmentName name of environment to remove statuses for // */ // public void delete(String environmentName) { // thisCollection.deleteMany(eq("environmentName", environmentName)); // } // // // /** // * Replace existing last statuses for environment by new ones // * @param environmentName environment to update statuses // * @param resources new statuses to be set up // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) { // delete(environmentName); // // List<Document> dbResources = resources.stream() // .map(rs -> DocumentMapper.resourceStatusToDocument(environmentName, rs)) // .collect(Collectors.toList()); // // thisCollection.insertMany(dbResources); // } // // // /** // * Get last statuses for environment resources // * @param environmentName environment to fetch statuses for // */ // public List<ResourceStatus> find(String environmentName) { // List<ResourceStatus> resources = thisCollection.find(new Document().append("environmentName", environmentName)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for multiple environments // * // * @param environmentNames environments to fetch statuses for // * @return // */ // public List<ResourceStatus> find(Collection<String> environmentNames) { // List<ResourceStatus> resources = thisCollection.find(in("environmentName", environmentNames)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for particular environment and defined resources // * @param environmentName environment to fetch statuses for // * @param resourceIds resources to fetch statuses for // * @return // */ // public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) { // Bson query = and( // eq("environmentName", environmentName), // in("resource.resourceId", resourceIds) // ); // // List<ResourceStatus> resources = thisCollection.find(query) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // }
import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceLastStatusDAO; import java.util.List; import java.util.Set; import java.util.stream.Collectors;
package org.yagel.monitor.runner.test.intergation.dao; public class ResourceLastStatusDAOTest extends AbstractDAOTest { private ResourceLastStatusDAO lastStatusDAO; private String environmentName = this.getClass().getSimpleName(); private int resourcesCount = 5; @BeforeClass public void loadDao() throws Exception {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java // public class ResourceLastStatusDAO extends AbstractDAO { // // private final static String COLLECTION_NAME = "ResourceLastStatus"; // private MongoCollection<Document> thisCollection; // // // public ResourceLastStatusDAO(MongoDatabase db) { // super(db); // thisCollection = db.getCollection(COLLECTION_NAME); // } // // // /** // * Remove all last statuses for particular environment // * @param environmentName name of environment to remove statuses for // */ // public void delete(String environmentName) { // thisCollection.deleteMany(eq("environmentName", environmentName)); // } // // // /** // * Replace existing last statuses for environment by new ones // * @param environmentName environment to update statuses // * @param resources new statuses to be set up // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) { // delete(environmentName); // // List<Document> dbResources = resources.stream() // .map(rs -> DocumentMapper.resourceStatusToDocument(environmentName, rs)) // .collect(Collectors.toList()); // // thisCollection.insertMany(dbResources); // } // // // /** // * Get last statuses for environment resources // * @param environmentName environment to fetch statuses for // */ // public List<ResourceStatus> find(String environmentName) { // List<ResourceStatus> resources = thisCollection.find(new Document().append("environmentName", environmentName)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for multiple environments // * // * @param environmentNames environments to fetch statuses for // * @return // */ // public List<ResourceStatus> find(Collection<String> environmentNames) { // List<ResourceStatus> resources = thisCollection.find(in("environmentName", environmentNames)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for particular environment and defined resources // * @param environmentName environment to fetch statuses for // * @param resourceIds resources to fetch statuses for // * @return // */ // public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) { // Bson query = and( // eq("environmentName", environmentName), // in("resource.resourceId", resourceIds) // ); // // List<ResourceStatus> resources = thisCollection.find(query) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceLastStatusDAOTest.java import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceLastStatusDAO; import java.util.List; import java.util.Set; import java.util.stream.Collectors; package org.yagel.monitor.runner.test.intergation.dao; public class ResourceLastStatusDAOTest extends AbstractDAOTest { private ResourceLastStatusDAO lastStatusDAO; private String environmentName = this.getClass().getSimpleName(); private int resourcesCount = 5; @BeforeClass public void loadDao() throws Exception {
lastStatusDAO = MongoConnector.getInstance().getLastStatusDAO();
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceLastStatusDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java // public class ResourceLastStatusDAO extends AbstractDAO { // // private final static String COLLECTION_NAME = "ResourceLastStatus"; // private MongoCollection<Document> thisCollection; // // // public ResourceLastStatusDAO(MongoDatabase db) { // super(db); // thisCollection = db.getCollection(COLLECTION_NAME); // } // // // /** // * Remove all last statuses for particular environment // * @param environmentName name of environment to remove statuses for // */ // public void delete(String environmentName) { // thisCollection.deleteMany(eq("environmentName", environmentName)); // } // // // /** // * Replace existing last statuses for environment by new ones // * @param environmentName environment to update statuses // * @param resources new statuses to be set up // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) { // delete(environmentName); // // List<Document> dbResources = resources.stream() // .map(rs -> DocumentMapper.resourceStatusToDocument(environmentName, rs)) // .collect(Collectors.toList()); // // thisCollection.insertMany(dbResources); // } // // // /** // * Get last statuses for environment resources // * @param environmentName environment to fetch statuses for // */ // public List<ResourceStatus> find(String environmentName) { // List<ResourceStatus> resources = thisCollection.find(new Document().append("environmentName", environmentName)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for multiple environments // * // * @param environmentNames environments to fetch statuses for // * @return // */ // public List<ResourceStatus> find(Collection<String> environmentNames) { // List<ResourceStatus> resources = thisCollection.find(in("environmentName", environmentNames)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for particular environment and defined resources // * @param environmentName environment to fetch statuses for // * @param resourceIds resources to fetch statuses for // * @return // */ // public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) { // Bson query = and( // eq("environmentName", environmentName), // in("resource.resourceId", resourceIds) // ); // // List<ResourceStatus> resources = thisCollection.find(query) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // }
import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceLastStatusDAO; import java.util.List; import java.util.Set; import java.util.stream.Collectors;
package org.yagel.monitor.runner.test.intergation.dao; public class ResourceLastStatusDAOTest extends AbstractDAOTest { private ResourceLastStatusDAO lastStatusDAO; private String environmentName = this.getClass().getSimpleName(); private int resourcesCount = 5; @BeforeClass public void loadDao() throws Exception { lastStatusDAO = MongoConnector.getInstance().getLastStatusDAO(); } @Test public void testInsertFindMultiple() throws Exception {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java // public class MongoConnector { // // private final static String MONITOR_DB = "monitor_tmp_newDomain"; // private final static Logger log = Logger.getLogger(MongoConnector.class); // private static MongoConnector connector; // // private MongoDatabase db; // private MongoClient client; // // // private MongoConnector() throws DiagnosticException { // client = new MongoClient(); // db = client.getDatabase(MONITOR_DB); // // } // // private MongoConnector(String connectURIStr) throws DiagnosticException { // MongoClientURI clientURI = new MongoClientURI(connectURIStr); // client = new MongoClient(clientURI); // String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase(); // db = client.getDatabase(dbName); // // } // // public static MongoConnector getInstance() { // if (connector == null) { // try { // String mongoConnectURI = System.getProperty("mongo.connect.uri", null); // if (mongoConnectURI == null) // connector = new MongoConnector(); // else // connector = new MongoConnector(mongoConnectURI); // } catch (Exception e) { // log.error("Exception on mongoDB connection creation. ", e); // throw new RuntimeException(e); // } // } // return connector; // } // // // public ResourceLastStatusDAO getLastStatusDAO() { // return new ResourceLastStatusDAO(db); // } // // public ResourceStatusDetailDAO getMonthDetailDAO() { // return new ResourceStatusDetailDAO(db); // } // // public AggregatedStatusDAO getAggregatedStatusDAO() { // return new AggregatedStatusDAO(db); // } // // public ResourceDAO getResourceDAO() { // return new ResourceDAO(db); // } // // // public void close() { // client.close(); // connector = null; // } // // // } // // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java // public class ResourceLastStatusDAO extends AbstractDAO { // // private final static String COLLECTION_NAME = "ResourceLastStatus"; // private MongoCollection<Document> thisCollection; // // // public ResourceLastStatusDAO(MongoDatabase db) { // super(db); // thisCollection = db.getCollection(COLLECTION_NAME); // } // // // /** // * Remove all last statuses for particular environment // * @param environmentName name of environment to remove statuses for // */ // public void delete(String environmentName) { // thisCollection.deleteMany(eq("environmentName", environmentName)); // } // // // /** // * Replace existing last statuses for environment by new ones // * @param environmentName environment to update statuses // * @param resources new statuses to be set up // */ // public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) { // delete(environmentName); // // List<Document> dbResources = resources.stream() // .map(rs -> DocumentMapper.resourceStatusToDocument(environmentName, rs)) // .collect(Collectors.toList()); // // thisCollection.insertMany(dbResources); // } // // // /** // * Get last statuses for environment resources // * @param environmentName environment to fetch statuses for // */ // public List<ResourceStatus> find(String environmentName) { // List<ResourceStatus> resources = thisCollection.find(new Document().append("environmentName", environmentName)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for multiple environments // * // * @param environmentNames environments to fetch statuses for // * @return // */ // public List<ResourceStatus> find(Collection<String> environmentNames) { // List<ResourceStatus> resources = thisCollection.find(in("environmentName", environmentNames)) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // // /** // * Get last statuses for particular environment and defined resources // * @param environmentName environment to fetch statuses for // * @param resourceIds resources to fetch statuses for // * @return // */ // public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) { // Bson query = and( // eq("environmentName", environmentName), // in("resource.resourceId", resourceIds) // ); // // List<ResourceStatus> resources = thisCollection.find(query) // .map(DocumentMapper::resourceStatusFromDocument) // .into(new ArrayList<>()); // // return resources; // } // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceLastStatusDAOTest.java import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.mongo.MongoConnector; import org.yagel.monitor.mongo.ResourceLastStatusDAO; import java.util.List; import java.util.Set; import java.util.stream.Collectors; package org.yagel.monitor.runner.test.intergation.dao; public class ResourceLastStatusDAOTest extends AbstractDAOTest { private ResourceLastStatusDAO lastStatusDAO; private String environmentName = this.getClass().getSimpleName(); private int resourcesCount = 5; @BeforeClass public void loadDao() throws Exception { lastStatusDAO = MongoConnector.getInstance().getLastStatusDAO(); } @Test public void testInsertFindMultiple() throws Exception {
List<ResourceStatus> statusList = generateN(resourcesCount, this::rndResStatus);
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/AbstractTimeRangeDAO.java
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/utils/DataUtils.java // public class DataUtils { // // /** // * @param date // * @return aggregated year and month values of given date field. Month is counted from 0 // * <p/> // * For example: // * If date is 2015-02-03 then return value will be 201501 // */ // public static int joinYearMonthValues(Date date) { // Calendar calendar = DateUtils.toCalendar(date); // return joinYearMonthValues(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)); // } // // public static int joinYearMonthValues(int year, int month) { // return year * 100 + month; // } // // public static Date getYesterday(Date currentDate) { // return DateUtils.addDays(currentDate, -1); // } // // public static boolean isToday(LocalDateTime localDateTime) { // return localDateTime.getDayOfYear() == LocalDateTime.now().getDayOfYear(); // } // // public static Date asDate(LocalDate localDate) { // return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); // } // // public static Date asDate(LocalDateTime localDateTime) { // return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); // } // // public static LocalDate asLocalDate(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate(); // } // // public static LocalDateTime asLocalDateTime(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); // } // // public static List<Integer> getMonthNumbersInDateFrame(Date startDate, Date endDate) { // List<Integer> dates = new ArrayList<>(); // // LocalDateTime start = asLocalDateTime(startDate); // LocalDateTime end = asLocalDateTime(endDate); // // // while (start.isBefore(end) || start.equals(end)) { // dates.add(start.getMonthValue()); // start = start.plusMonths(1); // } // return dates; // // } // // public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException { // // List<Date[]> dates = new ArrayList<>(); // // LocalDateTime dFrom = asLocalDateTime(from); // LocalDateTime dTo = asLocalDateTime(to); // // if (dFrom.compareTo(dTo) >= 0) { // throw new IllegalArgumentException("Provide a to-date greater than the from-date"); // } // // while (dFrom.compareTo(dTo) < 0) { // // check if current time frame is last // boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear(); // // // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date // int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); // LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX; // // // // build timeframe // Date[] dar = new Date[2]; // dar[0] = asDate(dFrom); // dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time)); // // // add current timeframe // dates.add(dar); // // // jump to beginning of next month // dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay(); // } // // return dates; // // } // // // }
import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; import org.yagel.monitor.utils.DataUtils; import java.util.Date;
package org.yagel.monitor.mongo; public abstract class AbstractTimeRangeDAO extends AbstractDAO { protected final static String COLLECTION_NAME = "ResourceMonthDetail%s"; protected MongoCollection<Document> thisCollection; protected int thisDate = -1; public AbstractTimeRangeDAO(MongoDatabase mongoDatabase) { super(mongoDatabase); } protected void switchCollection(Date date) {
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/utils/DataUtils.java // public class DataUtils { // // /** // * @param date // * @return aggregated year and month values of given date field. Month is counted from 0 // * <p/> // * For example: // * If date is 2015-02-03 then return value will be 201501 // */ // public static int joinYearMonthValues(Date date) { // Calendar calendar = DateUtils.toCalendar(date); // return joinYearMonthValues(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)); // } // // public static int joinYearMonthValues(int year, int month) { // return year * 100 + month; // } // // public static Date getYesterday(Date currentDate) { // return DateUtils.addDays(currentDate, -1); // } // // public static boolean isToday(LocalDateTime localDateTime) { // return localDateTime.getDayOfYear() == LocalDateTime.now().getDayOfYear(); // } // // public static Date asDate(LocalDate localDate) { // return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); // } // // public static Date asDate(LocalDateTime localDateTime) { // return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); // } // // public static LocalDate asLocalDate(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate(); // } // // public static LocalDateTime asLocalDateTime(Date date) { // return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); // } // // public static List<Integer> getMonthNumbersInDateFrame(Date startDate, Date endDate) { // List<Integer> dates = new ArrayList<>(); // // LocalDateTime start = asLocalDateTime(startDate); // LocalDateTime end = asLocalDateTime(endDate); // // // while (start.isBefore(end) || start.equals(end)) { // dates.add(start.getMonthValue()); // start = start.plusMonths(1); // } // return dates; // // } // // public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException { // // List<Date[]> dates = new ArrayList<>(); // // LocalDateTime dFrom = asLocalDateTime(from); // LocalDateTime dTo = asLocalDateTime(to); // // if (dFrom.compareTo(dTo) >= 0) { // throw new IllegalArgumentException("Provide a to-date greater than the from-date"); // } // // while (dFrom.compareTo(dTo) < 0) { // // check if current time frame is last // boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear(); // // // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date // int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); // LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX; // // // // build timeframe // Date[] dar = new Date[2]; // dar[0] = asDate(dFrom); // dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time)); // // // add current timeframe // dates.add(dar); // // // jump to beginning of next month // dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay(); // } // // return dates; // // } // // // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/AbstractTimeRangeDAO.java import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; import org.yagel.monitor.utils.DataUtils; import java.util.Date; package org.yagel.monitor.mongo; public abstract class AbstractTimeRangeDAO extends AbstractDAO { protected final static String COLLECTION_NAME = "ResourceMonthDetail%s"; protected MongoCollection<Document> thisCollection; protected int thisDate = -1; public AbstractTimeRangeDAO(MongoDatabase mongoDatabase) { super(mongoDatabase); } protected void switchCollection(Date date) {
int toDate = DataUtils.joinYearMonthValues(date);
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/status/collector/ProxyCollectorLoader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // }
import org.apache.log4j.Logger; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector;
package org.yagel.monitor.status.collector; public class ProxyCollectorLoader implements MonitorStatusCollectorLoader { private final static Logger log = Logger.getLogger(ProxyCollectorLoader.class); private final MonitorStatusCollectorLoader originalLoader; public ProxyCollectorLoader(MonitorStatusCollectorLoader originalLoader) { this.originalLoader = originalLoader; } @Override
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/status/collector/ProxyCollectorLoader.java import org.apache.log4j.Logger; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector; package org.yagel.monitor.status.collector; public class ProxyCollectorLoader implements MonitorStatusCollectorLoader { private final static Logger log = Logger.getLogger(ProxyCollectorLoader.class); private final MonitorStatusCollectorLoader originalLoader; public ProxyCollectorLoader(MonitorStatusCollectorLoader originalLoader) { this.originalLoader = originalLoader; } @Override
public MonitorStatusCollector loadCollector(EnvironmentConfig config) {
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/status/collector/ProxyCollectorLoader.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // }
import org.apache.log4j.Logger; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector;
package org.yagel.monitor.status.collector; public class ProxyCollectorLoader implements MonitorStatusCollectorLoader { private final static Logger log = Logger.getLogger(ProxyCollectorLoader.class); private final MonitorStatusCollectorLoader originalLoader; public ProxyCollectorLoader(MonitorStatusCollectorLoader originalLoader) { this.originalLoader = originalLoader; } @Override
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/status/collector/ProxyCollectorLoader.java import org.apache.log4j.Logger; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector; package org.yagel.monitor.status.collector; public class ProxyCollectorLoader implements MonitorStatusCollectorLoader { private final static Logger log = Logger.getLogger(ProxyCollectorLoader.class); private final MonitorStatusCollectorLoader originalLoader; public ProxyCollectorLoader(MonitorStatusCollectorLoader originalLoader) { this.originalLoader = originalLoader; } @Override
public MonitorStatusCollector loadCollector(EnvironmentConfig config) {
YagelNasManit/environment.monitor
environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/dto/EnvironmentStatusDTO.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // }
import org.yagel.monitor.ResourceStatus; import java.util.List;
package org.yagel.monitor.api.rest.dto; public class EnvironmentStatusDTO { private String name;
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // Path: environment.monitor.server/src/main/java/org/yagel/monitor/api/rest/dto/EnvironmentStatusDTO.java import org.yagel.monitor.ResourceStatus; import java.util.List; package org.yagel.monitor.api.rest.dto; public class EnvironmentStatusDTO { private String name;
private List<ResourceStatus> resourcesStatus;
YagelNasManit/environment.monitor
environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.monitor.resource.Status; import java.util.Date;
package org.yagel.monitor; public interface ResourceStatus { Resource getResource(); void setResource(Resource resource);
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java import org.yagel.monitor.resource.Status; import java.util.Date; package org.yagel.monitor; public interface ResourceStatus { Resource getResource(); void setResource(Resource resource);
Status getStatus();
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/extension/TestAddJarToClassPath.java
// Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java // public class JarScanner { // // private final static Logger log = Logger.getLogger(JarScanner.class); // private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml"; // private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class; // private final ClassLoader classLoader; // private Class classProvider; // private String pathToJar; // private String cannonicalJarPath; // // public JarScanner(ClassLoader classLoader, String pathToJar) { // this.classLoader = classLoader; // this.pathToJar = pathToJar; // this.cannonicalJarPath = "jar:file:" + pathToJar + "!/"; // } // // public void scanJar() { // // URL[] urls; // try { // urls = new URL[]{new URL(cannonicalJarPath)}; // } catch (IOException e) { // throw new PluginException("Unable to locate plugin jar by path provided", e); // } // // // try (JarFile jarFile = new JarFile(pathToJar); URLClassLoader cl = URLClassLoader.newInstance(urls, classLoader)) { // // Enumeration<JarEntry> e = jarFile.entries(); // // while (e.hasMoreElements()) { // JarEntry je = e.nextElement(); // // log.debug("File found: " + je.getName()); // if (je.isDirectory() || !je.getName().endsWith(".class")) { // log.debug("not a class, skip"); // continue; // } // // // -6 because of .class // String className = je.getName().substring(0, je.getName().length() - 6); // className = className.replace('/', '.'); // // // try { // log.debug("External class found: " + className); // Class c = cl.loadClass(className); // log.debug("Loaded class : " + className); // // if (loaderClass.isAssignableFrom(c)) { // classProvider = c; // log.debug("Found implementation of loader class, taking as plugin provider : " + className); // } // } catch (ClassNotFoundException ex) { // throw new PluginException("For some reason was unable to load class from plugin jar", ex); // } // } // // } catch (IOException e) { // throw new PluginException("Exception occurred during loading plugin jar", e); // } // // // } // // public MonitorStatusCollectorLoader getStatusCollectorLoader() { // try { // return (MonitorStatusCollectorLoader) classProvider.newInstance(); // } catch (InstantiationException | IllegalAccessException e) { // throw new PluginException("Unable to instantiate plugin collector class", e); // } // } // // public MonitorConfig getMonitorConfig() { // // // return new MonitorConfigReader().readMonitorConfig(cannonicalJarPath + MONITOR_CONFIG_FILE_NAME); // // } // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // }
import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.plugins.JarScanner; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import javax.xml.bind.JAXBException;
package org.yagel.monitor.runner.test.intergation.extension; public class TestAddJarToClassPath { @Test(enabled = false) public void testLoaderIsFound() throws ClassNotFoundException, IOException, IllegalAccessException, InstantiationException, JAXBException { String pathToLocalJar = System.getProperty("plugin.jar.location");//"/Users/oleh_kovalyshyn/Self_Development/Github/EnvMonitor/source/plugin-extension/target/plugin-extension-1.0-SNAPSHOT.jar";
// Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java // public class JarScanner { // // private final static Logger log = Logger.getLogger(JarScanner.class); // private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml"; // private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class; // private final ClassLoader classLoader; // private Class classProvider; // private String pathToJar; // private String cannonicalJarPath; // // public JarScanner(ClassLoader classLoader, String pathToJar) { // this.classLoader = classLoader; // this.pathToJar = pathToJar; // this.cannonicalJarPath = "jar:file:" + pathToJar + "!/"; // } // // public void scanJar() { // // URL[] urls; // try { // urls = new URL[]{new URL(cannonicalJarPath)}; // } catch (IOException e) { // throw new PluginException("Unable to locate plugin jar by path provided", e); // } // // // try (JarFile jarFile = new JarFile(pathToJar); URLClassLoader cl = URLClassLoader.newInstance(urls, classLoader)) { // // Enumeration<JarEntry> e = jarFile.entries(); // // while (e.hasMoreElements()) { // JarEntry je = e.nextElement(); // // log.debug("File found: " + je.getName()); // if (je.isDirectory() || !je.getName().endsWith(".class")) { // log.debug("not a class, skip"); // continue; // } // // // -6 because of .class // String className = je.getName().substring(0, je.getName().length() - 6); // className = className.replace('/', '.'); // // // try { // log.debug("External class found: " + className); // Class c = cl.loadClass(className); // log.debug("Loaded class : " + className); // // if (loaderClass.isAssignableFrom(c)) { // classProvider = c; // log.debug("Found implementation of loader class, taking as plugin provider : " + className); // } // } catch (ClassNotFoundException ex) { // throw new PluginException("For some reason was unable to load class from plugin jar", ex); // } // } // // } catch (IOException e) { // throw new PluginException("Exception occurred during loading plugin jar", e); // } // // // } // // public MonitorStatusCollectorLoader getStatusCollectorLoader() { // try { // return (MonitorStatusCollectorLoader) classProvider.newInstance(); // } catch (InstantiationException | IllegalAccessException e) { // throw new PluginException("Unable to instantiate plugin collector class", e); // } // } // // public MonitorConfig getMonitorConfig() { // // // return new MonitorConfigReader().readMonitorConfig(cannonicalJarPath + MONITOR_CONFIG_FILE_NAME); // // } // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/extension/TestAddJarToClassPath.java import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.plugins.JarScanner; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import javax.xml.bind.JAXBException; package org.yagel.monitor.runner.test.intergation.extension; public class TestAddJarToClassPath { @Test(enabled = false) public void testLoaderIsFound() throws ClassNotFoundException, IOException, IllegalAccessException, InstantiationException, JAXBException { String pathToLocalJar = System.getProperty("plugin.jar.location");//"/Users/oleh_kovalyshyn/Self_Development/Github/EnvMonitor/source/plugin-extension/target/plugin-extension-1.0-SNAPSHOT.jar";
JarScanner collectorFinder = new JarScanner(ClassLoader.getSystemClassLoader(), pathToLocalJar);
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/extension/TestAddJarToClassPath.java
// Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java // public class JarScanner { // // private final static Logger log = Logger.getLogger(JarScanner.class); // private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml"; // private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class; // private final ClassLoader classLoader; // private Class classProvider; // private String pathToJar; // private String cannonicalJarPath; // // public JarScanner(ClassLoader classLoader, String pathToJar) { // this.classLoader = classLoader; // this.pathToJar = pathToJar; // this.cannonicalJarPath = "jar:file:" + pathToJar + "!/"; // } // // public void scanJar() { // // URL[] urls; // try { // urls = new URL[]{new URL(cannonicalJarPath)}; // } catch (IOException e) { // throw new PluginException("Unable to locate plugin jar by path provided", e); // } // // // try (JarFile jarFile = new JarFile(pathToJar); URLClassLoader cl = URLClassLoader.newInstance(urls, classLoader)) { // // Enumeration<JarEntry> e = jarFile.entries(); // // while (e.hasMoreElements()) { // JarEntry je = e.nextElement(); // // log.debug("File found: " + je.getName()); // if (je.isDirectory() || !je.getName().endsWith(".class")) { // log.debug("not a class, skip"); // continue; // } // // // -6 because of .class // String className = je.getName().substring(0, je.getName().length() - 6); // className = className.replace('/', '.'); // // // try { // log.debug("External class found: " + className); // Class c = cl.loadClass(className); // log.debug("Loaded class : " + className); // // if (loaderClass.isAssignableFrom(c)) { // classProvider = c; // log.debug("Found implementation of loader class, taking as plugin provider : " + className); // } // } catch (ClassNotFoundException ex) { // throw new PluginException("For some reason was unable to load class from plugin jar", ex); // } // } // // } catch (IOException e) { // throw new PluginException("Exception occurred during loading plugin jar", e); // } // // // } // // public MonitorStatusCollectorLoader getStatusCollectorLoader() { // try { // return (MonitorStatusCollectorLoader) classProvider.newInstance(); // } catch (InstantiationException | IllegalAccessException e) { // throw new PluginException("Unable to instantiate plugin collector class", e); // } // } // // public MonitorConfig getMonitorConfig() { // // // return new MonitorConfigReader().readMonitorConfig(cannonicalJarPath + MONITOR_CONFIG_FILE_NAME); // // } // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // }
import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.plugins.JarScanner; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import javax.xml.bind.JAXBException;
package org.yagel.monitor.runner.test.intergation.extension; public class TestAddJarToClassPath { @Test(enabled = false) public void testLoaderIsFound() throws ClassNotFoundException, IOException, IllegalAccessException, InstantiationException, JAXBException { String pathToLocalJar = System.getProperty("plugin.jar.location");//"/Users/oleh_kovalyshyn/Self_Development/Github/EnvMonitor/source/plugin-extension/target/plugin-extension-1.0-SNAPSHOT.jar"; JarScanner collectorFinder = new JarScanner(ClassLoader.getSystemClassLoader(), pathToLocalJar); collectorFinder.scanJar();
// Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java // public class JarScanner { // // private final static Logger log = Logger.getLogger(JarScanner.class); // private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml"; // private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class; // private final ClassLoader classLoader; // private Class classProvider; // private String pathToJar; // private String cannonicalJarPath; // // public JarScanner(ClassLoader classLoader, String pathToJar) { // this.classLoader = classLoader; // this.pathToJar = pathToJar; // this.cannonicalJarPath = "jar:file:" + pathToJar + "!/"; // } // // public void scanJar() { // // URL[] urls; // try { // urls = new URL[]{new URL(cannonicalJarPath)}; // } catch (IOException e) { // throw new PluginException("Unable to locate plugin jar by path provided", e); // } // // // try (JarFile jarFile = new JarFile(pathToJar); URLClassLoader cl = URLClassLoader.newInstance(urls, classLoader)) { // // Enumeration<JarEntry> e = jarFile.entries(); // // while (e.hasMoreElements()) { // JarEntry je = e.nextElement(); // // log.debug("File found: " + je.getName()); // if (je.isDirectory() || !je.getName().endsWith(".class")) { // log.debug("not a class, skip"); // continue; // } // // // -6 because of .class // String className = je.getName().substring(0, je.getName().length() - 6); // className = className.replace('/', '.'); // // // try { // log.debug("External class found: " + className); // Class c = cl.loadClass(className); // log.debug("Loaded class : " + className); // // if (loaderClass.isAssignableFrom(c)) { // classProvider = c; // log.debug("Found implementation of loader class, taking as plugin provider : " + className); // } // } catch (ClassNotFoundException ex) { // throw new PluginException("For some reason was unable to load class from plugin jar", ex); // } // } // // } catch (IOException e) { // throw new PluginException("Exception occurred during loading plugin jar", e); // } // // // } // // public MonitorStatusCollectorLoader getStatusCollectorLoader() { // try { // return (MonitorStatusCollectorLoader) classProvider.newInstance(); // } catch (InstantiationException | IllegalAccessException e) { // throw new PluginException("Unable to instantiate plugin collector class", e); // } // } // // public MonitorConfig getMonitorConfig() { // // // return new MonitorConfigReader().readMonitorConfig(cannonicalJarPath + MONITOR_CONFIG_FILE_NAME); // // } // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/extension/TestAddJarToClassPath.java import org.testng.Assert; import org.testng.annotations.Test; import org.yagel.monitor.plugins.JarScanner; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import javax.xml.bind.JAXBException; package org.yagel.monitor.runner.test.intergation.extension; public class TestAddJarToClassPath { @Test(enabled = false) public void testLoaderIsFound() throws ClassNotFoundException, IOException, IllegalAccessException, InstantiationException, JAXBException { String pathToLocalJar = System.getProperty("plugin.jar.location");//"/Users/oleh_kovalyshyn/Self_Development/Github/EnvMonitor/source/plugin-extension/target/plugin-extension-1.0-SNAPSHOT.jar"; JarScanner collectorFinder = new JarScanner(ClassLoader.getSystemClassLoader(), pathToLocalJar); collectorFinder.scanJar();
MonitorStatusCollectorLoader loader = collectorFinder.getStatusCollectorLoader();
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/TestStatusCollector.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/AbstractResourceStatusProvider.java // public abstract class AbstractResourceStatusProvider implements ResourceStatusProvider { // // protected Resource resource; // protected EnvironmentConfig config; // protected int proviterVersion = 1; // // public AbstractResourceStatusProvider(EnvironmentConfig config) { // this.config = config; // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java // public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { // // public CoreApiServiceStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("API service", "Core API service of web site"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java // public class DataBaseStatusProvider extends AbstractResourceStatusProvider { // // // public DataBaseStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // // } // // @Override // public Resource getResource() { // return new ResourceImpl("DataBase", "Environment DataBase"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java // public class WebUIStatusProvider extends AbstractResourceStatusProvider { // // public WebUIStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("WebUI", "Web Site Web UI"); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // }
import org.apache.log4j.Logger; import org.yagel.environment.monitor.test.extension.provider.AbstractResourceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.CoreApiServiceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.DataBaseStatusProvider; import org.yagel.environment.monitor.test.extension.provider.WebUIStatusProvider; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceStatusImpl; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set;
package org.yagel.environment.monitor.test.extension; public class TestStatusCollector implements MonitorStatusCollector { private static final Logger log = Logger.getLogger(TestStatusCollector.class);
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/AbstractResourceStatusProvider.java // public abstract class AbstractResourceStatusProvider implements ResourceStatusProvider { // // protected Resource resource; // protected EnvironmentConfig config; // protected int proviterVersion = 1; // // public AbstractResourceStatusProvider(EnvironmentConfig config) { // this.config = config; // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java // public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { // // public CoreApiServiceStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("API service", "Core API service of web site"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java // public class DataBaseStatusProvider extends AbstractResourceStatusProvider { // // // public DataBaseStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // // } // // @Override // public Resource getResource() { // return new ResourceImpl("DataBase", "Environment DataBase"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java // public class WebUIStatusProvider extends AbstractResourceStatusProvider { // // public WebUIStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("WebUI", "Web Site Web UI"); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/TestStatusCollector.java import org.apache.log4j.Logger; import org.yagel.environment.monitor.test.extension.provider.AbstractResourceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.CoreApiServiceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.DataBaseStatusProvider; import org.yagel.environment.monitor.test.extension.provider.WebUIStatusProvider; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceStatusImpl; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; package org.yagel.environment.monitor.test.extension; public class TestStatusCollector implements MonitorStatusCollector { private static final Logger log = Logger.getLogger(TestStatusCollector.class);
private EnvironmentConfig config;
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/TestStatusCollector.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/AbstractResourceStatusProvider.java // public abstract class AbstractResourceStatusProvider implements ResourceStatusProvider { // // protected Resource resource; // protected EnvironmentConfig config; // protected int proviterVersion = 1; // // public AbstractResourceStatusProvider(EnvironmentConfig config) { // this.config = config; // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java // public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { // // public CoreApiServiceStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("API service", "Core API service of web site"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java // public class DataBaseStatusProvider extends AbstractResourceStatusProvider { // // // public DataBaseStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // // } // // @Override // public Resource getResource() { // return new ResourceImpl("DataBase", "Environment DataBase"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java // public class WebUIStatusProvider extends AbstractResourceStatusProvider { // // public WebUIStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("WebUI", "Web Site Web UI"); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // }
import org.apache.log4j.Logger; import org.yagel.environment.monitor.test.extension.provider.AbstractResourceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.CoreApiServiceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.DataBaseStatusProvider; import org.yagel.environment.monitor.test.extension.provider.WebUIStatusProvider; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceStatusImpl; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set;
package org.yagel.environment.monitor.test.extension; public class TestStatusCollector implements MonitorStatusCollector { private static final Logger log = Logger.getLogger(TestStatusCollector.class); private EnvironmentConfig config; public TestStatusCollector(EnvironmentConfig config) { this.config = config; } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/AbstractResourceStatusProvider.java // public abstract class AbstractResourceStatusProvider implements ResourceStatusProvider { // // protected Resource resource; // protected EnvironmentConfig config; // protected int proviterVersion = 1; // // public AbstractResourceStatusProvider(EnvironmentConfig config) { // this.config = config; // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/CoreApiServiceStatusProvider.java // public class CoreApiServiceStatusProvider extends AbstractResourceStatusProvider { // // public CoreApiServiceStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("API service", "Core API service of web site"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/DataBaseStatusProvider.java // public class DataBaseStatusProvider extends AbstractResourceStatusProvider { // // // public DataBaseStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // // } // // @Override // public Resource getResource() { // return new ResourceImpl("DataBase", "Environment DataBase"); // } // } // // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java // public class WebUIStatusProvider extends AbstractResourceStatusProvider { // // public WebUIStatusProvider(EnvironmentConfig config) { // super(config); // } // // @Override // public String getName() { // return null; // } // // @Override // public Status reloadStatus() { // return StatusRandomizer.random(); // } // // @Override // public Resource getResource() { // return new ResourceImpl("WebUI", "Web Site Web UI"); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorStatusCollector.java // public interface MonitorStatusCollector { // // // synchronise? // Set<ResourceStatus> updateStatus(); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/TestStatusCollector.java import org.apache.log4j.Logger; import org.yagel.environment.monitor.test.extension.provider.AbstractResourceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.CoreApiServiceStatusProvider; import org.yagel.environment.monitor.test.extension.provider.DataBaseStatusProvider; import org.yagel.environment.monitor.test.extension.provider.WebUIStatusProvider; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.MonitorStatusCollector; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceStatusImpl; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; package org.yagel.environment.monitor.test.extension; public class TestStatusCollector implements MonitorStatusCollector { private static final Logger log = Logger.getLogger(TestStatusCollector.class); private EnvironmentConfig config; public TestStatusCollector(EnvironmentConfig config) { this.config = config; } @Override
public Set<ResourceStatus> updateStatus() {
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/PluginException.java // public class PluginException extends RuntimeException { // // public PluginException(Throwable cause) { // super(cause); // } // // public PluginException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.plugins.exception.PluginException; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile;
package org.yagel.monitor.plugins; public class JarScanner { private final static Logger log = Logger.getLogger(JarScanner.class); private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml";
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/PluginException.java // public class PluginException extends RuntimeException { // // public PluginException(Throwable cause) { // super(cause); // } // // public PluginException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.plugins.exception.PluginException; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; package org.yagel.monitor.plugins; public class JarScanner { private final static Logger log = Logger.getLogger(JarScanner.class); private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml";
private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class;
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/PluginException.java // public class PluginException extends RuntimeException { // // public PluginException(Throwable cause) { // super(cause); // } // // public PluginException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.plugins.exception.PluginException; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile;
package org.yagel.monitor.plugins; public class JarScanner { private final static Logger log = Logger.getLogger(JarScanner.class); private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml"; private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class; private final ClassLoader classLoader; private Class classProvider; private String pathToJar; private String cannonicalJarPath; public JarScanner(ClassLoader classLoader, String pathToJar) { this.classLoader = classLoader; this.pathToJar = pathToJar; this.cannonicalJarPath = "jar:file:" + pathToJar + "!/"; } public void scanJar() { URL[] urls; try { urls = new URL[]{new URL(cannonicalJarPath)}; } catch (IOException e) {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/PluginException.java // public class PluginException extends RuntimeException { // // public PluginException(Throwable cause) { // super(cause); // } // // public PluginException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.plugins.exception.PluginException; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; package org.yagel.monitor.plugins; public class JarScanner { private final static Logger log = Logger.getLogger(JarScanner.class); private final static String MONITOR_CONFIG_FILE_NAME = "EnvMonitor.xml"; private final static Class<MonitorStatusCollectorLoader> loaderClass = MonitorStatusCollectorLoader.class; private final ClassLoader classLoader; private Class classProvider; private String pathToJar; private String cannonicalJarPath; public JarScanner(ClassLoader classLoader, String pathToJar) { this.classLoader = classLoader; this.pathToJar = pathToJar; this.cannonicalJarPath = "jar:file:" + pathToJar + "!/"; } public void scanJar() { URL[] urls; try { urls = new URL[]{new URL(cannonicalJarPath)}; } catch (IOException e) {
throw new PluginException("Unable to locate plugin jar by path provided", e);
YagelNasManit/environment.monitor
environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/PluginException.java // public class PluginException extends RuntimeException { // // public PluginException(Throwable cause) { // super(cause); // } // // public PluginException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // }
import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.plugins.exception.PluginException; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile;
try { log.debug("External class found: " + className); Class c = cl.loadClass(className); log.debug("Loaded class : " + className); if (loaderClass.isAssignableFrom(c)) { classProvider = c; log.debug("Found implementation of loader class, taking as plugin provider : " + className); } } catch (ClassNotFoundException ex) { throw new PluginException("For some reason was unable to load class from plugin jar", ex); } } } catch (IOException e) { throw new PluginException("Exception occurred during loading plugin jar", e); } } public MonitorStatusCollectorLoader getStatusCollectorLoader() { try { return (MonitorStatusCollectorLoader) classProvider.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new PluginException("Unable to instantiate plugin collector class", e); } }
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/MonitorConfig.java // public interface MonitorConfig { // // // Set<EnvironmentConfig> getEnvironments(); // // } // // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/exception/PluginException.java // public class PluginException extends RuntimeException { // // public PluginException(Throwable cause) { // super(cause); // } // // public PluginException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/status/collector/MonitorStatusCollectorLoader.java // public interface MonitorStatusCollectorLoader { // // // MonitorStatusCollector loadCollector(EnvironmentConfig config); // // } // Path: environment.monitor.plugins/src/main/java/org/yagel/monitor/plugins/JarScanner.java import org.apache.log4j.Logger; import org.yagel.monitor.MonitorConfig; import org.yagel.monitor.plugins.exception.PluginException; import org.yagel.monitor.status.collector.MonitorStatusCollectorLoader; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.Enumeration; import java.util.jar.JarEntry; import java.util.jar.JarFile; try { log.debug("External class found: " + className); Class c = cl.loadClass(className); log.debug("Loaded class : " + className); if (loaderClass.isAssignableFrom(c)) { classProvider = c; log.debug("Found implementation of loader class, taking as plugin provider : " + className); } } catch (ClassNotFoundException ex) { throw new PluginException("For some reason was unable to load class from plugin jar", ex); } } } catch (IOException e) { throw new PluginException("Exception occurred during loading plugin jar", e); } } public MonitorStatusCollectorLoader getStatusCollectorLoader() { try { return (MonitorStatusCollectorLoader) classProvider.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new PluginException("Unable to instantiate plugin collector class", e); } }
public MonitorConfig getMonitorConfig() {
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream;
package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name";
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name";
protected Resource rndResource() {
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream;
package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() {
return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID());
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream;
package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() { return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID()); }
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() { return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID()); }
protected ResourceStatus rndResStatus() {
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream;
package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() { return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID()); } protected ResourceStatus rndResStatus() { return this.rndResStatus(rndResource()); } protected ResourceStatus rndResStatus(Resource resource) {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() { return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID()); } protected ResourceStatus rndResStatus() { return this.rndResStatus(rndResource()); } protected ResourceStatus rndResStatus(Resource resource) {
return new ResourceStatusImpl(resource, rndStatus(), new Date());
YagelNasManit/environment.monitor
environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream;
package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() { return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID()); } protected ResourceStatus rndResStatus() { return this.rndResStatus(rndResource()); } protected ResourceStatus rndResStatus(Resource resource) { return new ResourceStatusImpl(resource, rndStatus(), new Date()); }
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceStatusImpl.java // public class ResourceStatusImpl implements ResourceStatus { // // private Resource resource; // private Status status; // private Date updated = new Date(); // // // public ResourceStatusImpl(Resource resource, Status status) { // this.resource = resource; // this.status = status; // } // // public ResourceStatusImpl(Resource resource, Status status, Date updated) { // this(resource, status); // this.updated = updated; // } // // // @Override // public Resource getResource() { // return resource; // } // // @Override // public void setResource(Resource resource) { // this.resource = resource; // } // // @Override // public Status getStatus() { // return status; // } // // @Override // public void setStatus(Status status) { // this.status = status; // } // // @Override // public Date getUpdated() { // return updated; // } // // @Override // public void setUpdated(Date updated) { // this.updated = updated; // } // // @Override // public int hashCode() { // return Objects.hash(getResource(), getStatus(), getUpdated()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceStatusImpl)) return false; // ResourceStatusImpl that = (ResourceStatusImpl) o; // return Objects.equals(getResource(), that.getResource()) && // getStatus() == that.getStatus() && // Objects.equals(getUpdated(), that.getUpdated()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("resource", resource) // .append("status", status) // .append("updated", updated) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/AbstractDAOTest.java import org.apache.commons.lang3.RandomUtils; import org.yagel.monitor.Resource; import org.yagel.monitor.ResourceStatus; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.ResourceStatusImpl; import org.yagel.monitor.resource.Status; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; package org.yagel.monitor.runner.test.intergation.dao; public class AbstractDAOTest { protected String mockResoureId = "Mock_resource"; protected String mockResoureName = "Mock_resource_Name"; protected Resource rndResource() { return new ResourceImpl(mockResoureId + UUID.randomUUID(), mockResoureName + UUID.randomUUID()); } protected ResourceStatus rndResStatus() { return this.rndResStatus(rndResource()); } protected ResourceStatus rndResStatus(Resource resource) { return new ResourceStatusImpl(resource, rndStatus(), new Date()); }
protected ResourceStatus rndResStatus(Resource resource, Status status, Date updated) {
YagelNasManit/environment.monitor
environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // }
import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.in; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; import org.bson.conversions.Bson; import org.yagel.monitor.ResourceStatus; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.stream.Collectors;
package org.yagel.monitor.mongo; public class ResourceLastStatusDAO extends AbstractDAO { private final static String COLLECTION_NAME = "ResourceLastStatus"; private MongoCollection<Document> thisCollection; public ResourceLastStatusDAO(MongoDatabase db) { super(db); thisCollection = db.getCollection(COLLECTION_NAME); } /** * Remove all last statuses for particular environment * @param environmentName name of environment to remove statuses for */ public void delete(String environmentName) { thisCollection.deleteMany(eq("environmentName", environmentName)); } /** * Replace existing last statuses for environment by new ones * @param environmentName environment to update statuses * @param resources new statuses to be set up */
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java // public interface ResourceStatus { // // Resource getResource(); // // void setResource(Resource resource); // // Status getStatus(); // // void setStatus(Status status); // // Date getUpdated(); // // void setUpdated(Date updated); // } // Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.eq; import static com.mongodb.client.model.Filters.in; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.Document; import org.bson.conversions.Bson; import org.yagel.monitor.ResourceStatus; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.stream.Collectors; package org.yagel.monitor.mongo; public class ResourceLastStatusDAO extends AbstractDAO { private final static String COLLECTION_NAME = "ResourceLastStatus"; private MongoCollection<Document> thisCollection; public ResourceLastStatusDAO(MongoDatabase db) { super(db); thisCollection = db.getCollection(COLLECTION_NAME); } /** * Remove all last statuses for particular environment * @param environmentName name of environment to remove statuses for */ public void delete(String environmentName) { thisCollection.deleteMany(eq("environmentName", environmentName)); } /** * Replace existing last statuses for environment by new ones * @param environmentName environment to update statuses * @param resources new statuses to be set up */
public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override
public Status reloadStatus() {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() {
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() {
return StatusRandomizer.random();
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override
public Resource getResource() {
YagelNasManit/environment.monitor
environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // }
import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status;
package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override public Resource getResource() {
// Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/util/StatusRandomizer.java // public class StatusRandomizer { // // public static Status random() { // int rnd = new Random().nextInt(Status.values().length); // return Status.values()[rnd]; // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/EnvironmentConfig.java // public interface EnvironmentConfig { // // String getEnvName(); // // String getHost(); // // long getTaskDelay(); // // int getAppVersion(); // // Set<String> getCheckResources(); // // Map<String, String> getAdditionalProperties(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/Resource.java // public interface Resource { // // String getId(); // // String getName(); // // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/ResourceImpl.java // public class ResourceImpl implements Resource { // // private String id; // private String name; // // // public ResourceImpl(String id, String name) { // this.id = id; // this.name = name; // } // // @Override // public String getId() { // return this.id; // } // // // @Override // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // @Override // public int hashCode() { // return Objects.hash(getId(), getName()); // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof ResourceImpl)) return false; // ResourceImpl resource = (ResourceImpl) o; // return Objects.equals(getId(), resource.getId()) && // Objects.equals(getName(), resource.getName()); // } // // @Override // public String toString() { // return new ToStringBuilder(this) // .append("id", id) // .append("name", name) // .toString(); // } // } // // Path: environment.monitor.core/src/main/java/org/yagel/monitor/resource/Status.java // public enum Status { // // @XmlEnumValue("Online") // Online(0), // s0 // @XmlEnumValue("BorderLine") // BorderLine(1), // s1 // @XmlEnumValue("Unavailable") // Unavailable(2), // s2 // @XmlEnumValue("Unknown") // Unknown(3); // s3 // // int seriaNumber; // // Status(int seriaNumber) { // this.seriaNumber = seriaNumber; // } // // public static int seriaNumbers() { // return 3; // } // // public static Status fromSerialNumber(int serialNumber) { // return Stream.of(Status.values()) // .filter(status -> status.getSeriaNumber() == serialNumber) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException("illegal resource status")); // } // // public int getSeriaNumber() { // return seriaNumber; // } // // // } // Path: environment.monitor.test.extension/src/main/java/org/yagel/environment/monitor/test/extension/provider/WebUIStatusProvider.java import org.yagel.environment.monitor.test.util.StatusRandomizer; import org.yagel.monitor.EnvironmentConfig; import org.yagel.monitor.Resource; import org.yagel.monitor.resource.ResourceImpl; import org.yagel.monitor.resource.Status; package org.yagel.environment.monitor.test.extension.provider; public class WebUIStatusProvider extends AbstractResourceStatusProvider { public WebUIStatusProvider(EnvironmentConfig config) { super(config); } @Override public String getName() { return null; } @Override public Status reloadStatus() { return StatusRandomizer.random(); } @Override public Resource getResource() {
return new ResourceImpl("WebUI", "Web Site Web UI");
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/dao/OrderDao.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Order.java // public class Order { // // private String ordersID;//订单id // private Date orderTime;//下单时间 // private double total; //合计 // private int state; //订单的状态四种:1未付款 2已付款但未发货 3已发货但未确认收货 4已确认交易成功 // private User user; //下单的用户 // private String address; //收货地址 // private List<OrderItem> orderItemList;//当前订单下所有条目 // // // public List<OrderItem> getOrderItemList() { // return orderItemList; // } // public void setOrderItemList(List<OrderItem> orderItemList) { // this.orderItemList = orderItemList; // } // public String getOrdersID() { // return ordersID; // } // public void setOrdersID(String ordersID) { // this.ordersID = ordersID; // } // public Date getOrderTime() { // return orderTime; // } // public void setOrderTime(Date orderTimel) { // this.orderTime = orderTimel; // } // public double getTotal() { // return total; // } // public void setTotal(double total) { // this.total = total; // } // public int getState() { // return state; // } // public void setState(int state) { // this.state = state; // } // public User getUser() { // return user; // } // public void setUser(User user) { // this.user = user; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/OrderItem.java // public class OrderItem { // // private String orderitemID; //订单项id // private int count; //数量 // private double subtotal;//小计 // private Order order;//所属订单 // private Commodity commodity;//所要购买的商品 // // public String getOrderitemID() { // return orderitemID; // } // public void setOrderitemID(String orderitemID) { // this.orderitemID = orderitemID; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public double getSubtotal() { // return subtotal; // } // public void setSubtotal(double subtotal) { // this.subtotal = subtotal; // } // public Order getOrder() { // return order; // } // public void setOrder(Order order) { // this.order = order; // } // public Commodity getCommodity() { // return commodity; // } // public void setCommodity(Commodity commodity) { // this.commodity = commodity; // } // // // // }
import java.util.List; import com.greengrocer.freshmarket.domain.Order; import com.greengrocer.freshmarket.domain.OrderItem;
package com.greengrocer.freshmarket.dao; public interface OrderDao { /** * 添加订单 * @param order */ public void addOrder(Order order); /** * 插入订单条目 * @param orderItemList */
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Order.java // public class Order { // // private String ordersID;//订单id // private Date orderTime;//下单时间 // private double total; //合计 // private int state; //订单的状态四种:1未付款 2已付款但未发货 3已发货但未确认收货 4已确认交易成功 // private User user; //下单的用户 // private String address; //收货地址 // private List<OrderItem> orderItemList;//当前订单下所有条目 // // // public List<OrderItem> getOrderItemList() { // return orderItemList; // } // public void setOrderItemList(List<OrderItem> orderItemList) { // this.orderItemList = orderItemList; // } // public String getOrdersID() { // return ordersID; // } // public void setOrdersID(String ordersID) { // this.ordersID = ordersID; // } // public Date getOrderTime() { // return orderTime; // } // public void setOrderTime(Date orderTimel) { // this.orderTime = orderTimel; // } // public double getTotal() { // return total; // } // public void setTotal(double total) { // this.total = total; // } // public int getState() { // return state; // } // public void setState(int state) { // this.state = state; // } // public User getUser() { // return user; // } // public void setUser(User user) { // this.user = user; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/OrderItem.java // public class OrderItem { // // private String orderitemID; //订单项id // private int count; //数量 // private double subtotal;//小计 // private Order order;//所属订单 // private Commodity commodity;//所要购买的商品 // // public String getOrderitemID() { // return orderitemID; // } // public void setOrderitemID(String orderitemID) { // this.orderitemID = orderitemID; // } // public int getCount() { // return count; // } // public void setCount(int count) { // this.count = count; // } // public double getSubtotal() { // return subtotal; // } // public void setSubtotal(double subtotal) { // this.subtotal = subtotal; // } // public Order getOrder() { // return order; // } // public void setOrder(Order order) { // this.order = order; // } // public Commodity getCommodity() { // return commodity; // } // public void setCommodity(Commodity commodity) { // this.commodity = commodity; // } // // // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/dao/OrderDao.java import java.util.List; import com.greengrocer.freshmarket.domain.Order; import com.greengrocer.freshmarket.domain.OrderItem; package com.greengrocer.freshmarket.dao; public interface OrderDao { /** * 添加订单 * @param order */ public void addOrder(Order order); /** * 插入订单条目 * @param orderItemList */
public void addOrderItemList(List<OrderItem> orderItemList);
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/dao/UserDao.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/web/formbean/UpdatePasswordForm.java // public class UpdatePasswordForm { // private String username; // private String oldpassword; // private String newpassword1; // private String newpassword2; // private Map<String,String> errors = new HashMap<String, String>() ; //存放错误集合 // // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public Map<String, String> getErrors() { // return errors; // } // public void setErrors(Map<String, String> errors) { // this.errors = errors; // } // public String getOldpassword() { // return oldpassword; // } // public void setOldpassword(String oldpassword) { // this.oldpassword = oldpassword; // } // public String getNewpassword1() { // return newpassword1; // } // public void setNewpassword1(String newpassword1) { // this.newpassword1 = newpassword1; // } // public String getNewpassword2() { // return newpassword2; // } // public void setNewpassword2(String newpassword2) { // this.newpassword2 = newpassword2; // } // // //密码不能为空,并且是3-8位数字 // //确认密码不能为空,并且和一次一致 // // public boolean validate(){ // boolean isOK = true; // if(oldpassword==null){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // }else if(oldpassword.length()==0){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // } // if(newpassword1==null){ // isOK = false; // errors.put("newpassword1", "新密码密码不能为空!!"); // }else{ // if(newpassword1.length() < 3 || newpassword1.length() > 15){ // errors.put("newpassword1", "新密码密码长度必须在3~15之间!!"); // isOK = false; // } // } // // if(newpassword2==null){ // errors.put("newpassword2", "确认密码不能为空!!"); // isOK = false; // }else{ // if(!newpassword1.equals(newpassword2)){ // errors.put("newpassword2", "两次密码要一致!!"); // isOK = false; // } // } // return isOK; // } // // }
import com.greengrocer.freshmarket.domain.User; import com.greengrocer.freshmarket.web.formbean.UpdatePasswordForm;
package com.greengrocer.freshmarket.dao; public interface UserDao { /** * 添加用户 * @param form 提交的用户表单对象 */ public void addUser(User form); /** * 根据用户名查询用户 * @param username 用户名 * @return 用户对象 */ public User findByUsername(String username); /** * 完善用户信息 * @param user */ public void complementUser(User user); /** * 修改收货地址 * @param address */ public void changeAddress(User user); /** * 修改密码 * @param form */
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/web/formbean/UpdatePasswordForm.java // public class UpdatePasswordForm { // private String username; // private String oldpassword; // private String newpassword1; // private String newpassword2; // private Map<String,String> errors = new HashMap<String, String>() ; //存放错误集合 // // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public Map<String, String> getErrors() { // return errors; // } // public void setErrors(Map<String, String> errors) { // this.errors = errors; // } // public String getOldpassword() { // return oldpassword; // } // public void setOldpassword(String oldpassword) { // this.oldpassword = oldpassword; // } // public String getNewpassword1() { // return newpassword1; // } // public void setNewpassword1(String newpassword1) { // this.newpassword1 = newpassword1; // } // public String getNewpassword2() { // return newpassword2; // } // public void setNewpassword2(String newpassword2) { // this.newpassword2 = newpassword2; // } // // //密码不能为空,并且是3-8位数字 // //确认密码不能为空,并且和一次一致 // // public boolean validate(){ // boolean isOK = true; // if(oldpassword==null){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // }else if(oldpassword.length()==0){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // } // if(newpassword1==null){ // isOK = false; // errors.put("newpassword1", "新密码密码不能为空!!"); // }else{ // if(newpassword1.length() < 3 || newpassword1.length() > 15){ // errors.put("newpassword1", "新密码密码长度必须在3~15之间!!"); // isOK = false; // } // } // // if(newpassword2==null){ // errors.put("newpassword2", "确认密码不能为空!!"); // isOK = false; // }else{ // if(!newpassword1.equals(newpassword2)){ // errors.put("newpassword2", "两次密码要一致!!"); // isOK = false; // } // } // return isOK; // } // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/dao/UserDao.java import com.greengrocer.freshmarket.domain.User; import com.greengrocer.freshmarket.web.formbean.UpdatePasswordForm; package com.greengrocer.freshmarket.dao; public interface UserDao { /** * 添加用户 * @param form 提交的用户表单对象 */ public void addUser(User form); /** * 根据用户名查询用户 * @param username 用户名 * @return 用户对象 */ public User findByUsername(String username); /** * 完善用户信息 * @param user */ public void complementUser(User user); /** * 修改收货地址 * @param address */ public void changeAddress(User user); /** * 修改密码 * @param form */
public void changePassword(UpdatePasswordForm form);
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/web/filter/UserFilter.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // }
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.domain.User;
package com.greengrocer.freshmarket.web.filter; public class UserFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); Object obj = session.getAttribute("sessionUser");
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/web/filter/UserFilter.java import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.domain.User; package com.greengrocer.freshmarket.web.filter; public class UserFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); Object obj = session.getAttribute("sessionUser");
if(obj!=null && obj instanceof Admin){
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/web/filter/UserFilter.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // }
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.domain.User;
package com.greengrocer.freshmarket.web.filter; public class UserFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); Object obj = session.getAttribute("sessionUser"); if(obj!=null && obj instanceof Admin){ //是管理员,放行 chain.doFilter(request, response);
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/web/filter/UserFilter.java import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.domain.User; package com.greengrocer.freshmarket.web.filter; public class UserFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); Object obj = session.getAttribute("sessionUser"); if(obj!=null && obj instanceof Admin){ //是管理员,放行 chain.doFilter(request, response);
}else if(obj!=null && obj instanceof User){
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/web/filter/AdminFilter.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // }
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.domain.User;
package com.greengrocer.freshmarket.web.filter; public class AdminFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //根据session中的用户对象的Type属性来判断是否为管理员 HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); //从session中获取用户对象 Object obj = session.getAttribute("sessionUser");
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/domain/User.java // public class User implements Serializable{ //实现序列化是因为设置了session钝化 // // private int userID; //用户编号 // private String username; //用户名 // private String password; //密码 // private String sex; //性别 // private String address; //住址 // private String phone; //联系电话 // private String email; //Email地址 // // // public int getUserID() { // return userID; // } // // public void setUserID(int userID) { // this.userID = userID; // } // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public String getSex() { // return sex; // } // public void setSex(String sex) { // this.sex = sex; // } // public String getAddress() { // return address; // } // public void setAddress(String address) { // this.address = address; // } // public String getPhone() { // return phone; // } // public void setPhone(String phone) { // this.phone = phone; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/web/filter/AdminFilter.java import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.domain.User; package com.greengrocer.freshmarket.web.filter; public class AdminFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //根据session中的用户对象的Type属性来判断是否为管理员 HttpServletRequest req = (HttpServletRequest)request; HttpSession session = req.getSession(); //从session中获取用户对象 Object obj = session.getAttribute("sessionUser");
if(obj!=null && obj instanceof Admin){
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/web/servlet/VerifyCodeServlet.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/utils/VerifyCode.java // public class VerifyCode { // private int w = 100; // private int h = 40; // private Random r = new Random(); // private String[] fontNames = {"宋体", "华文楷体", "黑体", "华文新魏", "华文隶书", "微软雅黑", "楷体_GB2312"}; // private String codes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // private Color bgColor = new Color(240, 240, 240); // private String text ; // // private Color randomColor () { // int red = r.nextInt(256); // int green = r.nextInt(256); // int blue = r.nextInt(256); // return new Color(red, green, blue); // } // // private Font randomFont () { // int index = r.nextInt(fontNames.length); // String fontName = fontNames[index]; // int style = r.nextInt(4); // int size = r.nextInt(5) + 24; // return new Font(fontName, style, size); // } // // private void drawLine (BufferedImage image) { // int num = 5; // Graphics2D g2 = (Graphics2D)image.getGraphics(); // for(int i = 0; i < num; i++) { // int x1 = r.nextInt(w); // int y1 = r.nextInt(h); // int x2 = r.nextInt(w); // int y2 = r.nextInt(h); // g2.setStroke(new BasicStroke(1.5F)); // g2.setColor(Color.BLUE); // g2.drawLine(x1, y1, x2, y2); // } // } // // private char randomChar () { // int index = r.nextInt(codes.length()); // return codes.charAt(index); // } // // private BufferedImage createImage () { // BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); // Graphics2D g2 = (Graphics2D)image.getGraphics(); // g2.setColor(this.bgColor); // g2.fillRect(0, 0, w, h); // return image; // } // // public BufferedImage getImage () { // BufferedImage image = createImage(); // Graphics2D g2 = (Graphics2D)image.getGraphics(); // StringBuilder sb = new StringBuilder(); // // 向图片中画4个字符 // for(int i = 0; i < 4; i++) { // String s = randomChar() + ""; // sb.append(s); // float x = i * 1.0F * w / 4; // g2.setFont(randomFont()); // g2.setColor(randomColor()); // g2.drawString(s, x, 22); // } // this.text = sb.toString(); // drawLine(image); // return image; // } // // /** // * 返回验证码的内容 // */ // public String getText () { // return text; // } // // public static void output (BufferedImage image, OutputStream out) // throws IOException { // ImageIO.write(image, "JPEG", out); // } // }
import java.awt.image.BufferedImage; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.greengrocer.freshmarket.utils.VerifyCode;
package com.greengrocer.freshmarket.web.servlet; public class VerifyCodeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* * 1. 创建验证码类 */
// Path: FreshMarket/src/com/greengrocer/freshmarket/utils/VerifyCode.java // public class VerifyCode { // private int w = 100; // private int h = 40; // private Random r = new Random(); // private String[] fontNames = {"宋体", "华文楷体", "黑体", "华文新魏", "华文隶书", "微软雅黑", "楷体_GB2312"}; // private String codes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // private Color bgColor = new Color(240, 240, 240); // private String text ; // // private Color randomColor () { // int red = r.nextInt(256); // int green = r.nextInt(256); // int blue = r.nextInt(256); // return new Color(red, green, blue); // } // // private Font randomFont () { // int index = r.nextInt(fontNames.length); // String fontName = fontNames[index]; // int style = r.nextInt(4); // int size = r.nextInt(5) + 24; // return new Font(fontName, style, size); // } // // private void drawLine (BufferedImage image) { // int num = 5; // Graphics2D g2 = (Graphics2D)image.getGraphics(); // for(int i = 0; i < num; i++) { // int x1 = r.nextInt(w); // int y1 = r.nextInt(h); // int x2 = r.nextInt(w); // int y2 = r.nextInt(h); // g2.setStroke(new BasicStroke(1.5F)); // g2.setColor(Color.BLUE); // g2.drawLine(x1, y1, x2, y2); // } // } // // private char randomChar () { // int index = r.nextInt(codes.length()); // return codes.charAt(index); // } // // private BufferedImage createImage () { // BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); // Graphics2D g2 = (Graphics2D)image.getGraphics(); // g2.setColor(this.bgColor); // g2.fillRect(0, 0, w, h); // return image; // } // // public BufferedImage getImage () { // BufferedImage image = createImage(); // Graphics2D g2 = (Graphics2D)image.getGraphics(); // StringBuilder sb = new StringBuilder(); // // 向图片中画4个字符 // for(int i = 0; i < 4; i++) { // String s = randomChar() + ""; // sb.append(s); // float x = i * 1.0F * w / 4; // g2.setFont(randomFont()); // g2.setColor(randomColor()); // g2.drawString(s, x, 22); // } // this.text = sb.toString(); // drawLine(image); // return image; // } // // /** // * 返回验证码的内容 // */ // public String getText () { // return text; // } // // public static void output (BufferedImage image, OutputStream out) // throws IOException { // ImageIO.write(image, "JPEG", out); // } // } // Path: FreshMarket/src/com/greengrocer/freshmarket/web/servlet/VerifyCodeServlet.java import java.awt.image.BufferedImage; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.greengrocer.freshmarket.utils.VerifyCode; package com.greengrocer.freshmarket.web.servlet; public class VerifyCodeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* * 1. 创建验证码类 */
VerifyCode vc = new VerifyCode();
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/web/servlet/CommodityTypeServlet.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/CommodityType.java // public class CommodityType implements Serializable{ //实现序列化是因为设置了session钝化 // // private int commodityTypeID; //商品种类编号 // private String commodityTypeName; //商品种类名称 // // // // public int getCommodityTypeID() { // return commodityTypeID; // } // public void setCommodityTypeID(int commodityTypeID) { // this.commodityTypeID = commodityTypeID; // } // public String getCommodityTypeName() { // return commodityTypeName; // } // public void setCommodityTypeName(String commodityTypeName) { // this.commodityTypeName = commodityTypeName; // } // @Override // public String toString() { // return "CommodityType [commodityTypeID=" + commodityTypeID // + ", commodityTypeName=" + commodityTypeName + "]"; // } // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/service/CommodityTypeService.java // public class CommodityTypeService { // // // 把具体的实现类的创建,隐藏到工厂中了 // private CommodityTypeDao commodityTypDao = DaoFactory.getCommodityTypeDao(); // // /** // * 返回带逗号拼接的商品(种类编号:商品种类)名称字符串 // * @return 商品种类字符串 // */ // public String getAllCommodityType(){ // List<CommodityType> types = commodityTypDao.findAllCommodityType(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i<types.size(); i++) { // CommodityType type = types.get(i); // sb.append(type.getCommodityTypeID()+":"+type.getCommodityTypeName()); // if(i<types.size()-1){ // sb.append(","); // } // } // return sb.toString(); // } // // // /** // * 返回所有的商品种类集合 // * @return 商品种类集合 // */ // public List<CommodityType> getAllCommodityTypes(){ // return commodityTypDao.findAllCommodityType(); // } // // // /** // * 添加商品种类 // * @param commodityType // */ // public void addCommodityType(CommodityType commodityType) { // commodityTypDao.addCommodityType(commodityType); // // } // // // /** // * 查询商品种类 // * @param commodityTypeID // * @return // */ // public CommodityType findCommodityType(String commodityTypeID) { // return commodityTypDao.findCommodityType(commodityTypeID); // // } // // // /** // * 修改商品种类 // * @param commodityType // */ // public void updateCommodityType(CommodityType commodityType) { // commodityTypDao.updateCommodityType(commodityType); // } // // /** // * 删除商品种类 // * @param commodityTypeID // */ // public void deleteCommodityType(String commodityTypeID) { // commodityTypDao.deleteCommodityType(commodityTypeID); // } // // // /** // * 查询商品种类 // * @param commodityTypeID // * @return // */ // public CommodityType findCommodityTypeByName(String commodityTypeName) { // return commodityTypDao.findCommodityTypeByName(commodityTypeName); // // } // // // }
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.greengrocer.freshmarket.domain.CommodityType; import com.greengrocer.freshmarket.service.CommodityTypeService;
package com.greengrocer.freshmarket.web.servlet; public class CommodityTypeServlet extends BaseServlet { private CommodityTypeService service = new CommodityTypeService(); /** * 得到所有的商品种类信息 * @param request * @param response */ public String getAllCommodityTypes(HttpServletRequest request, HttpServletResponse response){ request.setAttribute("commodityTypes", service.getAllCommodityTypes()); return "/adminjsps/admin/commodityType/list.jsp"; } /** * 获得商品种类信息 * @param request * @param response * @return */ public String findCommodityType(HttpServletRequest request, HttpServletResponse response){ String commodityTypeID = request.getParameter("commodityTypeID"); //根据id查询
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/CommodityType.java // public class CommodityType implements Serializable{ //实现序列化是因为设置了session钝化 // // private int commodityTypeID; //商品种类编号 // private String commodityTypeName; //商品种类名称 // // // // public int getCommodityTypeID() { // return commodityTypeID; // } // public void setCommodityTypeID(int commodityTypeID) { // this.commodityTypeID = commodityTypeID; // } // public String getCommodityTypeName() { // return commodityTypeName; // } // public void setCommodityTypeName(String commodityTypeName) { // this.commodityTypeName = commodityTypeName; // } // @Override // public String toString() { // return "CommodityType [commodityTypeID=" + commodityTypeID // + ", commodityTypeName=" + commodityTypeName + "]"; // } // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/service/CommodityTypeService.java // public class CommodityTypeService { // // // 把具体的实现类的创建,隐藏到工厂中了 // private CommodityTypeDao commodityTypDao = DaoFactory.getCommodityTypeDao(); // // /** // * 返回带逗号拼接的商品(种类编号:商品种类)名称字符串 // * @return 商品种类字符串 // */ // public String getAllCommodityType(){ // List<CommodityType> types = commodityTypDao.findAllCommodityType(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i<types.size(); i++) { // CommodityType type = types.get(i); // sb.append(type.getCommodityTypeID()+":"+type.getCommodityTypeName()); // if(i<types.size()-1){ // sb.append(","); // } // } // return sb.toString(); // } // // // /** // * 返回所有的商品种类集合 // * @return 商品种类集合 // */ // public List<CommodityType> getAllCommodityTypes(){ // return commodityTypDao.findAllCommodityType(); // } // // // /** // * 添加商品种类 // * @param commodityType // */ // public void addCommodityType(CommodityType commodityType) { // commodityTypDao.addCommodityType(commodityType); // // } // // // /** // * 查询商品种类 // * @param commodityTypeID // * @return // */ // public CommodityType findCommodityType(String commodityTypeID) { // return commodityTypDao.findCommodityType(commodityTypeID); // // } // // // /** // * 修改商品种类 // * @param commodityType // */ // public void updateCommodityType(CommodityType commodityType) { // commodityTypDao.updateCommodityType(commodityType); // } // // /** // * 删除商品种类 // * @param commodityTypeID // */ // public void deleteCommodityType(String commodityTypeID) { // commodityTypDao.deleteCommodityType(commodityTypeID); // } // // // /** // * 查询商品种类 // * @param commodityTypeID // * @return // */ // public CommodityType findCommodityTypeByName(String commodityTypeName) { // return commodityTypDao.findCommodityTypeByName(commodityTypeName); // // } // // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/web/servlet/CommodityTypeServlet.java import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.greengrocer.freshmarket.domain.CommodityType; import com.greengrocer.freshmarket.service.CommodityTypeService; package com.greengrocer.freshmarket.web.servlet; public class CommodityTypeServlet extends BaseServlet { private CommodityTypeService service = new CommodityTypeService(); /** * 得到所有的商品种类信息 * @param request * @param response */ public String getAllCommodityTypes(HttpServletRequest request, HttpServletResponse response){ request.setAttribute("commodityTypes", service.getAllCommodityTypes()); return "/adminjsps/admin/commodityType/list.jsp"; } /** * 获得商品种类信息 * @param request * @param response * @return */ public String findCommodityType(HttpServletRequest request, HttpServletResponse response){ String commodityTypeID = request.getParameter("commodityTypeID"); //根据id查询
CommodityType commodityType = service.findCommodityType(commodityTypeID);
cckevincyh/FreshMarket
FreshMarket/src/com/greengrocer/freshmarket/dao/AdminDao.java
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/web/formbean/UpdatePasswordForm.java // public class UpdatePasswordForm { // private String username; // private String oldpassword; // private String newpassword1; // private String newpassword2; // private Map<String,String> errors = new HashMap<String, String>() ; //存放错误集合 // // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public Map<String, String> getErrors() { // return errors; // } // public void setErrors(Map<String, String> errors) { // this.errors = errors; // } // public String getOldpassword() { // return oldpassword; // } // public void setOldpassword(String oldpassword) { // this.oldpassword = oldpassword; // } // public String getNewpassword1() { // return newpassword1; // } // public void setNewpassword1(String newpassword1) { // this.newpassword1 = newpassword1; // } // public String getNewpassword2() { // return newpassword2; // } // public void setNewpassword2(String newpassword2) { // this.newpassword2 = newpassword2; // } // // //密码不能为空,并且是3-8位数字 // //确认密码不能为空,并且和一次一致 // // public boolean validate(){ // boolean isOK = true; // if(oldpassword==null){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // }else if(oldpassword.length()==0){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // } // if(newpassword1==null){ // isOK = false; // errors.put("newpassword1", "新密码密码不能为空!!"); // }else{ // if(newpassword1.length() < 3 || newpassword1.length() > 15){ // errors.put("newpassword1", "新密码密码长度必须在3~15之间!!"); // isOK = false; // } // } // // if(newpassword2==null){ // errors.put("newpassword2", "确认密码不能为空!!"); // isOK = false; // }else{ // if(!newpassword1.equals(newpassword2)){ // errors.put("newpassword2", "两次密码要一致!!"); // isOK = false; // } // } // return isOK; // } // // }
import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.web.formbean.UpdatePasswordForm;
package com.greengrocer.freshmarket.dao; public interface AdminDao { /** * 添加管理员 * @param form 提交的管理员表单对象 */ public void addAdmin(Admin form); /** * 根据管理员用户名查询出管理员 * @param adminname 管理员用户名 * @return 管理员对象 */ public Admin findByAdminname(String adminname); /** * 修改密码 * @param admin * @param newPass */
// Path: FreshMarket/src/com/greengrocer/freshmarket/domain/Admin.java // public class Admin implements Serializable{ //实现序列化是因为设置了session钝化 // // private int adminID; //管理员编号 // private String username;//管理员用户名 // private String password; //管理员密码 // // // // // // // // public int getAdminID() { // return adminID; // } // // // public void setAdminID(int adminID) { // this.adminID = adminID; // } // // // // // public String getUsername() { // return username; // } // // // public void setUsername(String username) { // this.username = username; // } // // // public String getPassword() { // return password; // } // // // public void setPassword(String password) { // this.password = password; // } // // // // // // // } // // Path: FreshMarket/src/com/greengrocer/freshmarket/web/formbean/UpdatePasswordForm.java // public class UpdatePasswordForm { // private String username; // private String oldpassword; // private String newpassword1; // private String newpassword2; // private Map<String,String> errors = new HashMap<String, String>() ; //存放错误集合 // // // public String getUsername() { // return username; // } // public void setUsername(String username) { // this.username = username; // } // public Map<String, String> getErrors() { // return errors; // } // public void setErrors(Map<String, String> errors) { // this.errors = errors; // } // public String getOldpassword() { // return oldpassword; // } // public void setOldpassword(String oldpassword) { // this.oldpassword = oldpassword; // } // public String getNewpassword1() { // return newpassword1; // } // public void setNewpassword1(String newpassword1) { // this.newpassword1 = newpassword1; // } // public String getNewpassword2() { // return newpassword2; // } // public void setNewpassword2(String newpassword2) { // this.newpassword2 = newpassword2; // } // // //密码不能为空,并且是3-8位数字 // //确认密码不能为空,并且和一次一致 // // public boolean validate(){ // boolean isOK = true; // if(oldpassword==null){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // }else if(oldpassword.length()==0){ // isOK = false; // errors.put("oldpassword", "原密码不能为空!!"); // } // if(newpassword1==null){ // isOK = false; // errors.put("newpassword1", "新密码密码不能为空!!"); // }else{ // if(newpassword1.length() < 3 || newpassword1.length() > 15){ // errors.put("newpassword1", "新密码密码长度必须在3~15之间!!"); // isOK = false; // } // } // // if(newpassword2==null){ // errors.put("newpassword2", "确认密码不能为空!!"); // isOK = false; // }else{ // if(!newpassword1.equals(newpassword2)){ // errors.put("newpassword2", "两次密码要一致!!"); // isOK = false; // } // } // return isOK; // } // // } // Path: FreshMarket/src/com/greengrocer/freshmarket/dao/AdminDao.java import com.greengrocer.freshmarket.domain.Admin; import com.greengrocer.freshmarket.web.formbean.UpdatePasswordForm; package com.greengrocer.freshmarket.dao; public interface AdminDao { /** * 添加管理员 * @param form 提交的管理员表单对象 */ public void addAdmin(Admin form); /** * 根据管理员用户名查询出管理员 * @param adminname 管理员用户名 * @return 管理员对象 */ public Admin findByAdminname(String adminname); /** * 修改密码 * @param admin * @param newPass */
public void changePassword(UpdatePasswordForm form);
ppareit/swiftp
app/src/main/java/be/ppareit/swiftp/FsSettings.java
// Path: app/src/main/java/be/ppareit/swiftp/server/FtpUser.java // public class FtpUser { // // final private String mUsername; // final private String mPassword; // final private String mChroot; // // public FtpUser(@NonNull String username, @NonNull String password, @NonNull String chroot) { // mUsername = username; // mPassword = password; // // final File rootPath = new File(chroot); // mChroot = rootPath.isDirectory() ? chroot : FsSettings.getDefaultChrootDir().getPath(); // // } // // public String getUsername() { // return mUsername; // } // // public String getPassword() { // return mPassword; // } // // public String getChroot() { // return mChroot; // } // }
import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.TreeSet; import be.ppareit.swiftp.server.FtpUser; import lombok.val; import android.content.Context; import android.content.SharedPreferences; import android.os.Environment; import android.preference.PreferenceManager; import android.util.Log; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.File;
/* Copyright 2011-2013 Pieter Pareit Copyright 2009 David Revell This file is part of SwiFTP. SwiFTP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SwiFTP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SwiFTP. If not, see <http://www.gnu.org/licenses/>. */ package be.ppareit.swiftp; public class FsSettings { private final static String TAG = FsSettings.class.getSimpleName();
// Path: app/src/main/java/be/ppareit/swiftp/server/FtpUser.java // public class FtpUser { // // final private String mUsername; // final private String mPassword; // final private String mChroot; // // public FtpUser(@NonNull String username, @NonNull String password, @NonNull String chroot) { // mUsername = username; // mPassword = password; // // final File rootPath = new File(chroot); // mChroot = rootPath.isDirectory() ? chroot : FsSettings.getDefaultChrootDir().getPath(); // // } // // public String getUsername() { // return mUsername; // } // // public String getPassword() { // return mPassword; // } // // public String getChroot() { // return mChroot; // } // } // Path: app/src/main/java/be/ppareit/swiftp/FsSettings.java import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.TreeSet; import be.ppareit.swiftp.server.FtpUser; import lombok.val; import android.content.Context; import android.content.SharedPreferences; import android.os.Environment; import android.preference.PreferenceManager; import android.util.Log; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.File; /* Copyright 2011-2013 Pieter Pareit Copyright 2009 David Revell This file is part of SwiFTP. SwiFTP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SwiFTP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SwiFTP. If not, see <http://www.gnu.org/licenses/>. */ package be.ppareit.swiftp; public class FsSettings { private final static String TAG = FsSettings.class.getSimpleName();
public static List<FtpUser> getUsers() {
ppareit/swiftp
app/src/main/java/be/ppareit/swiftp/server/CmdMFMT.java
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // }
import net.vrallev.android.cat.Cat; import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import be.ppareit.swiftp.Util; import android.util.Log;
/* Copyright 2014 Pieter Pareit This file is part of SwiFTP. SwiFTP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SwiFTP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SwiFTP. If not, see <http://www.gnu.org/licenses/>. */ package be.ppareit.swiftp.server; /** * CmdMFMT implements File Modification Time. See draft-somers-ftp-mfxx-04 in documentation. */ public class CmdMFMT extends FtpCmd implements Runnable { private String mInput; public CmdMFMT(SessionThread sessionThread, String input) { super(sessionThread); mInput = input; } @Override public void run() { Cat.d("run: MFMT executing, input: " + mInput); //Syntax: "MFMT" SP time-val SP pathname CRLF String parameter = getParameter(mInput); int splitPosition = parameter.indexOf(' '); if (splitPosition == -1) { sessionThread.writeString("500 wrong number of parameters\r\n"); Cat.d("run: MFMT failed, wrong number of parameters"); return; } String timeString = parameter.substring(0, splitPosition); String pathName = parameter.substring(splitPosition + 1); // Format of time-val: YYYYMMDDHHMMSS.ss, see rfc3659, p6 // BUG: The milliseconds part get's ignored SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss", Locale.US); df.setTimeZone(TimeZone.getTimeZone("UTC")); Date timeVal; try {
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // } // Path: app/src/main/java/be/ppareit/swiftp/server/CmdMFMT.java import net.vrallev.android.cat.Cat; import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import be.ppareit.swiftp.Util; import android.util.Log; /* Copyright 2014 Pieter Pareit This file is part of SwiFTP. SwiFTP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SwiFTP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SwiFTP. If not, see <http://www.gnu.org/licenses/>. */ package be.ppareit.swiftp.server; /** * CmdMFMT implements File Modification Time. See draft-somers-ftp-mfxx-04 in documentation. */ public class CmdMFMT extends FtpCmd implements Runnable { private String mInput; public CmdMFMT(SessionThread sessionThread, String input) { super(sessionThread); mInput = input; } @Override public void run() { Cat.d("run: MFMT executing, input: " + mInput); //Syntax: "MFMT" SP time-val SP pathname CRLF String parameter = getParameter(mInput); int splitPosition = parameter.indexOf(' '); if (splitPosition == -1) { sessionThread.writeString("500 wrong number of parameters\r\n"); Cat.d("run: MFMT failed, wrong number of parameters"); return; } String timeString = parameter.substring(0, splitPosition); String pathName = parameter.substring(splitPosition + 1); // Format of time-val: YYYYMMDDHHMMSS.ss, see rfc3659, p6 // BUG: The milliseconds part get's ignored SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss", Locale.US); df.setTimeZone(TimeZone.getTimeZone("UTC")); Date timeVal; try {
timeVal = Util.parseDate(timeString);
ppareit/swiftp
app/src/main/java/be/ppareit/swiftp/server/CmdMDTM.java
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // }
import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import be.ppareit.swiftp.Util; import android.util.Log;
/* Copyright 2014 Pieter Pareit This file is part of SwiFTP. SwiFTP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SwiFTP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SwiFTP. If not, see <http://www.gnu.org/licenses/>. */ package be.ppareit.swiftp.server; /** * Implements File Modification Time */ public class CmdMDTM extends FtpCmd implements Runnable { private static final String TAG = CmdMDTM.class.getSimpleName(); private String mInput; public CmdMDTM(SessionThread sessionThread, String input) { super(sessionThread); mInput = input; } @Override public void run() { Log.d(TAG, "run: MDTM executing, input: " + mInput); String param = getParameter(mInput); File file = inputPathToChrootedFile(sessionThread.getChrootDir(), sessionThread.getWorkingDir(), param); if (file.exists()) { long lastModified = file.lastModified();
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // } // Path: app/src/main/java/be/ppareit/swiftp/server/CmdMDTM.java import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import be.ppareit.swiftp.Util; import android.util.Log; /* Copyright 2014 Pieter Pareit This file is part of SwiFTP. SwiFTP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SwiFTP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SwiFTP. If not, see <http://www.gnu.org/licenses/>. */ package be.ppareit.swiftp.server; /** * Implements File Modification Time */ public class CmdMDTM extends FtpCmd implements Runnable { private static final String TAG = CmdMDTM.class.getSimpleName(); private String mInput; public CmdMDTM(SessionThread sessionThread, String input) { super(sessionThread); mInput = input; } @Override public void run() { Log.d(TAG, "run: MDTM executing, input: " + mInput); String param = getParameter(mInput); File file = inputPathToChrootedFile(sessionThread.getChrootDir(), sessionThread.getWorkingDir(), param); if (file.exists()) { long lastModified = file.lastModified();
String response = "213 " + Util.getFtpDate(lastModified) + "\r\n";
ppareit/swiftp
app/src/main/java/be/ppareit/swiftp/AutoConnect.java
// Path: app/src/main/java/be/ppareit/android/BroadcastReceiverUtils.java // public static BroadcastReceiver createBroadcastReceiver(Receiver receiver) { // return new BroadcastReceiver() { // @Override // public void onReceive(Context context, Intent intent) { // receiver.onReceive(context, intent); // } // }; // }
import android.app.IntentService; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.IBinder; import androidx.core.app.NotificationCompat; import android.widget.Toast; import net.vrallev.android.cat.Cat; import static androidx.core.app.NotificationCompat.PRIORITY_MIN; import static androidx.core.content.ContextCompat.startForegroundService; import static be.ppareit.android.BroadcastReceiverUtils.createBroadcastReceiver;
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setPriority(PRIORITY_MIN) .setShowWhen(false) .setChannelId(channelId) .build(); startForeground(AutoConnect.NOTIFICATION_ID, notification); IntentFilter wifiStateChangedFilter = new IntentFilter(); wifiStateChangedFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); wifiStateChangedFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); registerReceiver(mWifiStateChangedReceiver, wifiStateChangedFilter); return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); stopForeground(true); try { unregisterReceiver(mWifiStateChangedReceiver); } catch (IllegalArgumentException e) { e.printStackTrace(); } } }
// Path: app/src/main/java/be/ppareit/android/BroadcastReceiverUtils.java // public static BroadcastReceiver createBroadcastReceiver(Receiver receiver) { // return new BroadcastReceiver() { // @Override // public void onReceive(Context context, Intent intent) { // receiver.onReceive(context, intent); // } // }; // } // Path: app/src/main/java/be/ppareit/swiftp/AutoConnect.java import android.app.IntentService; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.IBinder; import androidx.core.app.NotificationCompat; import android.widget.Toast; import net.vrallev.android.cat.Cat; import static androidx.core.app.NotificationCompat.PRIORITY_MIN; import static androidx.core.content.ContextCompat.startForegroundService; import static be.ppareit.android.BroadcastReceiverUtils.createBroadcastReceiver; .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setPriority(PRIORITY_MIN) .setShowWhen(false) .setChannelId(channelId) .build(); startForeground(AutoConnect.NOTIFICATION_ID, notification); IntentFilter wifiStateChangedFilter = new IntentFilter(); wifiStateChangedFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); wifiStateChangedFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); registerReceiver(mWifiStateChangedReceiver, wifiStateChangedFilter); return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); stopForeground(true); try { unregisterReceiver(mWifiStateChangedReceiver); } catch (IllegalArgumentException e) { e.printStackTrace(); } } }
private static BroadcastReceiver mWifiStateChangedReceiver = createBroadcastReceiver(
ppareit/swiftp
app/src/main/java/be/ppareit/swiftp/server/CmdMLSD.java
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // }
import java.io.File; import android.util.Log; import be.ppareit.swiftp.Util;
@Override protected String makeLsString(File file) { StringBuilder response = new StringBuilder(); if (!file.exists()) { Log.i(TAG, "makeLsString had nonexistent file"); return null; } // See Daniel Bernstein's explanation of /bin/ls format at: // http://cr.yp.to/ftp/list/binls.html // This stuff is almost entirely based on his recommendations. String lastNamePart = file.getName(); // Many clients can't handle files containing these symbols if (lastNamePart.contains("*") || lastNamePart.contains("/")) { Log.i(TAG, "Filename omitted due to disallowed character"); return null; } else { // The following line generates many calls in large directories // staticLog.l(Log.DEBUG, "Filename: " + lastNamePart); } String[] selectedTypes = sessionThread.getFormatTypes(); if(selectedTypes != null){ for (int i = 0; i < selectedTypes.length; ++i) { String type = selectedTypes[i]; if (type.equalsIgnoreCase("size")) { response.append("Size=" + String.valueOf(file.length()) + ';'); } else if (type.equalsIgnoreCase("modify")) {
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // } // Path: app/src/main/java/be/ppareit/swiftp/server/CmdMLSD.java import java.io.File; import android.util.Log; import be.ppareit.swiftp.Util; @Override protected String makeLsString(File file) { StringBuilder response = new StringBuilder(); if (!file.exists()) { Log.i(TAG, "makeLsString had nonexistent file"); return null; } // See Daniel Bernstein's explanation of /bin/ls format at: // http://cr.yp.to/ftp/list/binls.html // This stuff is almost entirely based on his recommendations. String lastNamePart = file.getName(); // Many clients can't handle files containing these symbols if (lastNamePart.contains("*") || lastNamePart.contains("/")) { Log.i(TAG, "Filename omitted due to disallowed character"); return null; } else { // The following line generates many calls in large directories // staticLog.l(Log.DEBUG, "Filename: " + lastNamePart); } String[] selectedTypes = sessionThread.getFormatTypes(); if(selectedTypes != null){ for (int i = 0; i < selectedTypes.length; ++i) { String type = selectedTypes[i]; if (type.equalsIgnoreCase("size")) { response.append("Size=" + String.valueOf(file.length()) + ';'); } else if (type.equalsIgnoreCase("modify")) {
String timeStr = Util.getFtpDate(file.lastModified());
ppareit/swiftp
app/src/main/java/be/ppareit/swiftp/server/CmdMLST.java
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // }
import be.ppareit.swiftp.Util; import java.io.File; import android.util.Log;
File fileToFormat = null; if(param.equals("")){ fileToFormat = sessionThread.getWorkingDir(); param = "/"; }else{ fileToFormat = inputPathToChrootedFile(sessionThread.getChrootDir(), sessionThread.getWorkingDir(), param); } if (fileToFormat.exists()) { sessionThread.writeString("250- Listing " + param + "\r\n"); sessionThread.writeString(makeString(fileToFormat) + "\r\n"); sessionThread.writeString("250 End\r\n"); } else { Log.w(TAG, "run: file does not exist"); sessionThread.writeString("550 file does not exist\r\n"); } Log.d(TAG, "run: LIST completed"); } public String makeString(File file){ StringBuilder response = new StringBuilder(); String[] selectedTypes = sessionThread.getFormatTypes(); if(selectedTypes != null){ for (int i = 0; i < selectedTypes.length; ++i) { String type = selectedTypes[i]; if (type.equalsIgnoreCase("size")) { response.append("Size=" + String.valueOf(file.length()) + ';'); } else if (type.equalsIgnoreCase("modify")) {
// Path: app/src/main/java/be/ppareit/swiftp/Util.java // abstract public class Util { // final static String TAG = Util.class.getSimpleName(); // // public static byte byteOfInt(int value, int which) { // int shift = which * 8; // return (byte) (value >> shift); // } // // public static String ipToString(int address, String sep) { // if (address > 0) { // StringBuffer buf = new StringBuffer(); // buf.append(byteOfInt(address, 0)).append(sep).append(byteOfInt(address, 1)) // .append(sep).append(byteOfInt(address, 2)).append(sep) // .append(byteOfInt(address, 3)); // Log.d(TAG, "ipToString returning: " + buf.toString()); // return buf.toString(); // } else { // return null; // } // } // // public static InetAddress intToInet(int value) { // byte[] bytes = new byte[4]; // for (int i = 0; i < 4; i++) { // bytes[i] = byteOfInt(value, i); // } // try { // return InetAddress.getByAddress(bytes); // } catch (UnknownHostException e) { // // This only happens if the byte array has a bad length // return null; // } // } // // public static String ipToString(int address) { // if (address == 0) { // // This can only occur due to an error, we shouldn't blindly // // convert 0 to string. // Log.e(TAG, "ipToString won't convert value 0"); // return null; // } // return ipToString(address, "."); // } // // public static String[] concatStrArrays(String[] a1, String[] a2) { // String[] retArr = new String[a1.length + a2.length]; // System.arraycopy(a1, 0, retArr, 0, a1.length); // System.arraycopy(a2, 0, retArr, a1.length, a2.length); // return retArr; // } // // public static void sleepIgnoreInterrupt(long millis) { // try { // Thread.sleep(millis); // } catch (InterruptedException ignored) { // } // } // // /** // * Creates a SimpleDateFormat in the formatting used by ftp sever/client. // */ // private static SimpleDateFormat createSimpleDateFormat() { // SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); // df.setTimeZone(TimeZone.getTimeZone("UTC")); // return df; // } // // public static String getFtpDate(long time) { // SimpleDateFormat df = createSimpleDateFormat(); // return df.format(new Date(time)); // } // // public static Date parseDate(String time) throws ParseException { // SimpleDateFormat df = createSimpleDateFormat(); // return df.parse(time); // } // } // Path: app/src/main/java/be/ppareit/swiftp/server/CmdMLST.java import be.ppareit.swiftp.Util; import java.io.File; import android.util.Log; File fileToFormat = null; if(param.equals("")){ fileToFormat = sessionThread.getWorkingDir(); param = "/"; }else{ fileToFormat = inputPathToChrootedFile(sessionThread.getChrootDir(), sessionThread.getWorkingDir(), param); } if (fileToFormat.exists()) { sessionThread.writeString("250- Listing " + param + "\r\n"); sessionThread.writeString(makeString(fileToFormat) + "\r\n"); sessionThread.writeString("250 End\r\n"); } else { Log.w(TAG, "run: file does not exist"); sessionThread.writeString("550 file does not exist\r\n"); } Log.d(TAG, "run: LIST completed"); } public String makeString(File file){ StringBuilder response = new StringBuilder(); String[] selectedTypes = sessionThread.getFormatTypes(); if(selectedTypes != null){ for (int i = 0; i < selectedTypes.length; ++i) { String type = selectedTypes[i]; if (type.equalsIgnoreCase("size")) { response.append("Size=" + String.valueOf(file.length()) + ';'); } else if (type.equalsIgnoreCase("modify")) {
String timeStr = Util.getFtpDate(file.lastModified());
gibffe/fuse
src/test/java/com/sulaco/fuse/netty/FuseChannelHandlerTest.java
// Path: src/test/java/com/sulaco/fuse/ActorAwareTest.java // @Ignore // public class ActorAwareTest { // // ActorSystem system = ActorSystem.create("test"); // // @Mock protected ApplicationContext mockAppCtx; // // @Mock protected AutowireCapableBeanFactory mockAutowireFactory; // // @Mock protected WireProtocol mockProto; // // @Mock protected Timer mockMeter; // // protected void setup() { // when(mockAppCtx.getAutowireCapableBeanFactory()).thenReturn(mockAutowireFactory); // } // // protected <T extends FuseEndpointActor> TestActorRef<T> mockEndpoint(Class<T> clazz) { // Props props = Props.create(clazz); // TestActorRef<T> testActorRef = TestActorRef.create(system, props); // testActorRef.underlyingActor().setProto(mockProto); // testActorRef.underlyingActor().autowire(mockAppCtx); // // return testActorRef; // } // // } // // Path: src/main/java/com/sulaco/fuse/akka/actor/RouteFinderActor.java // public class RouteFinderActor extends FuseEndpointActor { // // @Autowired protected RoutesConfig routes; // // @Override // protected void onRequest(final FuseRequestMessage message) { // // String uri = message.getRequest().getUri(); // // Optional<Route> route = routes.getFuseRoute(uri); // // if (route.isPresent()) { // Route rte = route.get(); // // // add route to the message // ((FuseRequestMessageImpl) message).setRoute(rte); // // // pass message to handling actor // rte.getHandler() // .getActor() // .ifPresent( // handler -> { // HttpMethod requested = message.getRequest().getMethod(); // HttpMethod supported = rte.getHandler().getHttpMethod(); // // if (supported.compareTo(requested) == 0) { // handler.tell(message, getSelf()); // } // else { // info(requested +" not supported by " + uri.toString()); // unhandled(message); // } // } // ); // } // else { // unhandled(message); // } // } // // public void setRoutes(RoutesConfig routes) { // this.routes = routes; // } // // }
import akka.testkit.TestActorRef; import com.sulaco.fuse.ActorAwareTest; import com.sulaco.fuse.akka.actor.RouteFinderActor; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpRequest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnit44Runner; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify;
package com.sulaco.fuse.netty; @RunWith(MockitoJUnit44Runner.class) public class FuseChannelHandlerTest extends ActorAwareTest { FuseChannelHandler instance;
// Path: src/test/java/com/sulaco/fuse/ActorAwareTest.java // @Ignore // public class ActorAwareTest { // // ActorSystem system = ActorSystem.create("test"); // // @Mock protected ApplicationContext mockAppCtx; // // @Mock protected AutowireCapableBeanFactory mockAutowireFactory; // // @Mock protected WireProtocol mockProto; // // @Mock protected Timer mockMeter; // // protected void setup() { // when(mockAppCtx.getAutowireCapableBeanFactory()).thenReturn(mockAutowireFactory); // } // // protected <T extends FuseEndpointActor> TestActorRef<T> mockEndpoint(Class<T> clazz) { // Props props = Props.create(clazz); // TestActorRef<T> testActorRef = TestActorRef.create(system, props); // testActorRef.underlyingActor().setProto(mockProto); // testActorRef.underlyingActor().autowire(mockAppCtx); // // return testActorRef; // } // // } // // Path: src/main/java/com/sulaco/fuse/akka/actor/RouteFinderActor.java // public class RouteFinderActor extends FuseEndpointActor { // // @Autowired protected RoutesConfig routes; // // @Override // protected void onRequest(final FuseRequestMessage message) { // // String uri = message.getRequest().getUri(); // // Optional<Route> route = routes.getFuseRoute(uri); // // if (route.isPresent()) { // Route rte = route.get(); // // // add route to the message // ((FuseRequestMessageImpl) message).setRoute(rte); // // // pass message to handling actor // rte.getHandler() // .getActor() // .ifPresent( // handler -> { // HttpMethod requested = message.getRequest().getMethod(); // HttpMethod supported = rte.getHandler().getHttpMethod(); // // if (supported.compareTo(requested) == 0) { // handler.tell(message, getSelf()); // } // else { // info(requested +" not supported by " + uri.toString()); // unhandled(message); // } // } // ); // } // else { // unhandled(message); // } // } // // public void setRoutes(RoutesConfig routes) { // this.routes = routes; // } // // } // Path: src/test/java/com/sulaco/fuse/netty/FuseChannelHandlerTest.java import akka.testkit.TestActorRef; import com.sulaco.fuse.ActorAwareTest; import com.sulaco.fuse.akka.actor.RouteFinderActor; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpRequest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnit44Runner; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; package com.sulaco.fuse.netty; @RunWith(MockitoJUnit44Runner.class) public class FuseChannelHandlerTest extends ActorAwareTest { FuseChannelHandler instance;
TestActorRef<RouteFinderActor> mockRouter;
gibffe/fuse
src/main/java/com/sulaco/fuse/netty/FuseChannelHandler.java
// Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // }
import com.sulaco.fuse.util.IdSource; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.http.HttpRequest; import akka.actor.ActorRef; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import static com.sulaco.fuse.util.IdSource.*;
package com.sulaco.fuse.netty; /** * Incoming requests are handled by a router actor - it will use a fixed pool of * child actors that will match the rest pattern to a preconfigured handling actor. * * @author gibffe * */ public class FuseChannelHandler extends ChannelInboundHandlerAdapter { protected ActorRef router; public FuseChannelHandler(ActorRef router) { super(); this.router = router; } @Override public void channelReadComplete(ChannelHandlerContext ctx) { //ctx.flush(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { router.tell(
// Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // } // Path: src/main/java/com/sulaco/fuse/netty/FuseChannelHandler.java import com.sulaco.fuse.util.IdSource; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.http.HttpRequest; import akka.actor.ActorRef; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import static com.sulaco.fuse.util.IdSource.*; package com.sulaco.fuse.netty; /** * Incoming requests are handled by a router actor - it will use a fixed pool of * child actors that will match the rest pattern to a preconfigured handling actor. * * @author gibffe * */ public class FuseChannelHandler extends ChannelInboundHandlerAdapter { protected ActorRef router; public FuseChannelHandler(ActorRef router) { super(); this.router = router; } @Override public void channelReadComplete(ChannelHandlerContext ctx) { //ctx.flush(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { router.tell(
new FuseRequestMessageImpl(IdSource.getLong(), ctx, (HttpRequest) msg),
gibffe/fuse
src/main/java/com/sulaco/fuse/netty/FuseChannelHandler.java
// Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // }
import com.sulaco.fuse.util.IdSource; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.http.HttpRequest; import akka.actor.ActorRef; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import static com.sulaco.fuse.util.IdSource.*;
package com.sulaco.fuse.netty; /** * Incoming requests are handled by a router actor - it will use a fixed pool of * child actors that will match the rest pattern to a preconfigured handling actor. * * @author gibffe * */ public class FuseChannelHandler extends ChannelInboundHandlerAdapter { protected ActorRef router; public FuseChannelHandler(ActorRef router) { super(); this.router = router; } @Override public void channelReadComplete(ChannelHandlerContext ctx) { //ctx.flush(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { router.tell(
// Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/util/IdSource.java // public class IdSource { // // static final AtomicInteger intSource = new AtomicInteger(0); // static final AtomicLong longSource = new AtomicLong(0); // // public static int getInt() { // return intSource.incrementAndGet(); // } // // public static long getLong() { // return longSource.incrementAndGet(); // } // // public static UUID getUUID() { // return UUID.randomUUID(); // } // // } // Path: src/main/java/com/sulaco/fuse/netty/FuseChannelHandler.java import com.sulaco.fuse.util.IdSource; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.http.HttpRequest; import akka.actor.ActorRef; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; import static com.sulaco.fuse.util.IdSource.*; package com.sulaco.fuse.netty; /** * Incoming requests are handled by a router actor - it will use a fixed pool of * child actors that will match the rest pattern to a preconfigured handling actor. * * @author gibffe * */ public class FuseChannelHandler extends ChannelInboundHandlerAdapter { protected ActorRef router; public FuseChannelHandler(ActorRef router) { super(); this.router = router; } @Override public void channelReadComplete(ChannelHandlerContext ctx) { //ctx.flush(); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { router.tell(
new FuseRequestMessageImpl(IdSource.getLong(), ctx, (HttpRequest) msg),
gibffe/fuse
examples/simple/src/main/java/com/sulaco/fuse/example/actor/NoopActor.java
// Path: src/main/java/com/sulaco/fuse/akka/actor/FuseEndpointActor.java // public abstract class FuseEndpointActor extends FuseBaseActor { // // @Autowired protected MetricsRegistry metrics; // // public FuseEndpointActor() { // super(); // } // // // TODO: refactor metrics // // meter = metrics.getRegistry().timer(getClass().getName()); // // @Override // public void onReceive(Object message) throws Exception { // try { // if (message instanceof FuseRequestMessage) { // onRequest((FuseRequestMessage) message); // //proto.error((FuseRequestMessage) message); // } // else { // super.onReceive(message); // } // } // catch (Exception ex) { // log.error("Error handling request !", ex); // unhandled(message); // } // finally { // // TODO: context flush // } // } // // protected void onRequest(final FuseRequestMessage request) { // // RouteHandler rhandler = request.getHandler(); // // Optional<String> method = rhandler.getMethodName(); // // if (method.isPresent()) { // // Invoke configured method instead of default 'onReceive'. Method needs to have correct // // signature, otherwise, fallback to 'onReceive' will occur. // // // Optional<Method> target = lookupMethod(this, method.get()); // if (target.isPresent()) { // try { // target.get() // .invoke(this, request); // } // catch (Exception ex) { // log.warn("[fuse] Invocation failure. x_x", ex); // } // } // } // else { // log.warn("[fuse] No handling method specified. Override onReceive. x_x"); // } // } // // // // @Override // public void unhandled(Object message) { // super.unhandled(message); // if (message instanceof FuseRequestMessage) { // proto.error((FuseRequestMessage) message); // } // } // // public void setProto(WireProtocol proto) { // this.proto = proto; // } // // protected static final Logger log = LoggerFactory.getLogger(FuseEndpointActor.class); // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessage.java // public interface FuseRequestMessage extends Route { // // long getId(); // // HttpRequest getRequest(); // // String getRequestBody(); // // ChannelHandlerContext getChannelContext(); // // void flush(); // // boolean flushed(); // // public <T> Optional<T> getParam(String name, Class<T> clazz); // // }
import com.sulaco.fuse.akka.actor.FuseEndpointActor; import com.sulaco.fuse.akka.message.FuseRequestMessage; import org.springframework.context.ApplicationContext;
package com.sulaco.fuse.example.actor; public class NoopActor extends FuseEndpointActor { @Override
// Path: src/main/java/com/sulaco/fuse/akka/actor/FuseEndpointActor.java // public abstract class FuseEndpointActor extends FuseBaseActor { // // @Autowired protected MetricsRegistry metrics; // // public FuseEndpointActor() { // super(); // } // // // TODO: refactor metrics // // meter = metrics.getRegistry().timer(getClass().getName()); // // @Override // public void onReceive(Object message) throws Exception { // try { // if (message instanceof FuseRequestMessage) { // onRequest((FuseRequestMessage) message); // //proto.error((FuseRequestMessage) message); // } // else { // super.onReceive(message); // } // } // catch (Exception ex) { // log.error("Error handling request !", ex); // unhandled(message); // } // finally { // // TODO: context flush // } // } // // protected void onRequest(final FuseRequestMessage request) { // // RouteHandler rhandler = request.getHandler(); // // Optional<String> method = rhandler.getMethodName(); // // if (method.isPresent()) { // // Invoke configured method instead of default 'onReceive'. Method needs to have correct // // signature, otherwise, fallback to 'onReceive' will occur. // // // Optional<Method> target = lookupMethod(this, method.get()); // if (target.isPresent()) { // try { // target.get() // .invoke(this, request); // } // catch (Exception ex) { // log.warn("[fuse] Invocation failure. x_x", ex); // } // } // } // else { // log.warn("[fuse] No handling method specified. Override onReceive. x_x"); // } // } // // // // @Override // public void unhandled(Object message) { // super.unhandled(message); // if (message instanceof FuseRequestMessage) { // proto.error((FuseRequestMessage) message); // } // } // // public void setProto(WireProtocol proto) { // this.proto = proto; // } // // protected static final Logger log = LoggerFactory.getLogger(FuseEndpointActor.class); // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessage.java // public interface FuseRequestMessage extends Route { // // long getId(); // // HttpRequest getRequest(); // // String getRequestBody(); // // ChannelHandlerContext getChannelContext(); // // void flush(); // // boolean flushed(); // // public <T> Optional<T> getParam(String name, Class<T> clazz); // // } // Path: examples/simple/src/main/java/com/sulaco/fuse/example/actor/NoopActor.java import com.sulaco.fuse.akka.actor.FuseEndpointActor; import com.sulaco.fuse.akka.message.FuseRequestMessage; import org.springframework.context.ApplicationContext; package com.sulaco.fuse.example.actor; public class NoopActor extends FuseEndpointActor { @Override
protected void onRequest(FuseRequestMessage request) {
gibffe/fuse
src/main/java/com/sulaco/fuse/config/ConfigSource.java
// Path: src/main/java/com/sulaco/fuse/config/route/RoutesConfig.java // public interface RoutesConfig { // // public void parse(); // // public Optional<Route> getFuseRoute(String uri); // // public void addEndpoint(ActorRef ref, String httpMethod, String path); // }
import com.sulaco.fuse.config.route.RoutesConfig; import com.typesafe.config.Config;
package com.sulaco.fuse.config; public interface ConfigSource { public void parseLocalConfig(); public Config getConfig();
// Path: src/main/java/com/sulaco/fuse/config/route/RoutesConfig.java // public interface RoutesConfig { // // public void parse(); // // public Optional<Route> getFuseRoute(String uri); // // public void addEndpoint(ActorRef ref, String httpMethod, String path); // } // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java import com.sulaco.fuse.config.route.RoutesConfig; import com.typesafe.config.Config; package com.sulaco.fuse.config; public interface ConfigSource { public void parseLocalConfig(); public Config getConfig();
public RoutesConfig getRoutesConfig();
gibffe/fuse
src/main/java/com/sulaco/fuse/akka/async/RequestSuspenderImpl.java
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseInternalMessage.java // public interface FuseInternalMessage extends FuseOriginChain { // // FuseMessageContext getContext(); // // long getRequestId(); // // long getTimestamp(); // // FuseInternalMessage timestamp(); // } // // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java // public interface ConfigSource { // // public void parseLocalConfig(); // // public Config getConfig(); // // public RoutesConfig getRoutesConfig(); // } // // Path: src/main/java/com/sulaco/fuse/config/actor/ActorFactory.java // public interface ActorFactory extends ActorSystemAware, ApplicationContextAware { // // public Optional<ActorRef> getLocalActor(String actorClass); // // public Optional<ActorRef> getLocalActor(String actorClass, String actorName); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, int spinCount); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, String actorName, int spinCount); // // public Optional<ActorRef> getLocalActorByRef(String ref); // // public Optional<ActorSelection> select(String path); // // public Iterable<ActorRef> getRoutees(String ref, Class<?> clazz, int spinCount); // // // }
import akka.actor.ActorSelection; import com.sulaco.fuse.akka.message.FuseInternalMessage; import com.sulaco.fuse.config.ConfigSource; import com.sulaco.fuse.config.actor.ActorFactory; import com.typesafe.config.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.NavigableMap; import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit;
package com.sulaco.fuse.akka.async; @Component public class RequestSuspenderImpl implements RequestSuspender {
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseInternalMessage.java // public interface FuseInternalMessage extends FuseOriginChain { // // FuseMessageContext getContext(); // // long getRequestId(); // // long getTimestamp(); // // FuseInternalMessage timestamp(); // } // // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java // public interface ConfigSource { // // public void parseLocalConfig(); // // public Config getConfig(); // // public RoutesConfig getRoutesConfig(); // } // // Path: src/main/java/com/sulaco/fuse/config/actor/ActorFactory.java // public interface ActorFactory extends ActorSystemAware, ApplicationContextAware { // // public Optional<ActorRef> getLocalActor(String actorClass); // // public Optional<ActorRef> getLocalActor(String actorClass, String actorName); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, int spinCount); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, String actorName, int spinCount); // // public Optional<ActorRef> getLocalActorByRef(String ref); // // public Optional<ActorSelection> select(String path); // // public Iterable<ActorRef> getRoutees(String ref, Class<?> clazz, int spinCount); // // // } // Path: src/main/java/com/sulaco/fuse/akka/async/RequestSuspenderImpl.java import akka.actor.ActorSelection; import com.sulaco.fuse.akka.message.FuseInternalMessage; import com.sulaco.fuse.config.ConfigSource; import com.sulaco.fuse.config.actor.ActorFactory; import com.typesafe.config.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.NavigableMap; import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; package com.sulaco.fuse.akka.async; @Component public class RequestSuspenderImpl implements RequestSuspender {
@Autowired ConfigSource configSource;
gibffe/fuse
src/main/java/com/sulaco/fuse/akka/async/RequestSuspenderImpl.java
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseInternalMessage.java // public interface FuseInternalMessage extends FuseOriginChain { // // FuseMessageContext getContext(); // // long getRequestId(); // // long getTimestamp(); // // FuseInternalMessage timestamp(); // } // // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java // public interface ConfigSource { // // public void parseLocalConfig(); // // public Config getConfig(); // // public RoutesConfig getRoutesConfig(); // } // // Path: src/main/java/com/sulaco/fuse/config/actor/ActorFactory.java // public interface ActorFactory extends ActorSystemAware, ApplicationContextAware { // // public Optional<ActorRef> getLocalActor(String actorClass); // // public Optional<ActorRef> getLocalActor(String actorClass, String actorName); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, int spinCount); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, String actorName, int spinCount); // // public Optional<ActorRef> getLocalActorByRef(String ref); // // public Optional<ActorSelection> select(String path); // // public Iterable<ActorRef> getRoutees(String ref, Class<?> clazz, int spinCount); // // // }
import akka.actor.ActorSelection; import com.sulaco.fuse.akka.message.FuseInternalMessage; import com.sulaco.fuse.config.ConfigSource; import com.sulaco.fuse.config.actor.ActorFactory; import com.typesafe.config.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.NavigableMap; import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit;
package com.sulaco.fuse.akka.async; @Component public class RequestSuspenderImpl implements RequestSuspender { @Autowired ConfigSource configSource;
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseInternalMessage.java // public interface FuseInternalMessage extends FuseOriginChain { // // FuseMessageContext getContext(); // // long getRequestId(); // // long getTimestamp(); // // FuseInternalMessage timestamp(); // } // // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java // public interface ConfigSource { // // public void parseLocalConfig(); // // public Config getConfig(); // // public RoutesConfig getRoutesConfig(); // } // // Path: src/main/java/com/sulaco/fuse/config/actor/ActorFactory.java // public interface ActorFactory extends ActorSystemAware, ApplicationContextAware { // // public Optional<ActorRef> getLocalActor(String actorClass); // // public Optional<ActorRef> getLocalActor(String actorClass, String actorName); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, int spinCount); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, String actorName, int spinCount); // // public Optional<ActorRef> getLocalActorByRef(String ref); // // public Optional<ActorSelection> select(String path); // // public Iterable<ActorRef> getRoutees(String ref, Class<?> clazz, int spinCount); // // // } // Path: src/main/java/com/sulaco/fuse/akka/async/RequestSuspenderImpl.java import akka.actor.ActorSelection; import com.sulaco.fuse.akka.message.FuseInternalMessage; import com.sulaco.fuse.config.ConfigSource; import com.sulaco.fuse.config.actor.ActorFactory; import com.typesafe.config.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.NavigableMap; import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; package com.sulaco.fuse.akka.async; @Component public class RequestSuspenderImpl implements RequestSuspender { @Autowired ConfigSource configSource;
@Autowired ActorFactory actorFactory;
gibffe/fuse
src/main/java/com/sulaco/fuse/akka/async/RequestSuspenderImpl.java
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseInternalMessage.java // public interface FuseInternalMessage extends FuseOriginChain { // // FuseMessageContext getContext(); // // long getRequestId(); // // long getTimestamp(); // // FuseInternalMessage timestamp(); // } // // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java // public interface ConfigSource { // // public void parseLocalConfig(); // // public Config getConfig(); // // public RoutesConfig getRoutesConfig(); // } // // Path: src/main/java/com/sulaco/fuse/config/actor/ActorFactory.java // public interface ActorFactory extends ActorSystemAware, ApplicationContextAware { // // public Optional<ActorRef> getLocalActor(String actorClass); // // public Optional<ActorRef> getLocalActor(String actorClass, String actorName); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, int spinCount); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, String actorName, int spinCount); // // public Optional<ActorRef> getLocalActorByRef(String ref); // // public Optional<ActorSelection> select(String path); // // public Iterable<ActorRef> getRoutees(String ref, Class<?> clazz, int spinCount); // // // }
import akka.actor.ActorSelection; import com.sulaco.fuse.akka.message.FuseInternalMessage; import com.sulaco.fuse.config.ConfigSource; import com.sulaco.fuse.config.actor.ActorFactory; import com.typesafe.config.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.NavigableMap; import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit;
package com.sulaco.fuse.akka.async; @Component public class RequestSuspenderImpl implements RequestSuspender { @Autowired ConfigSource configSource; @Autowired ActorFactory actorFactory; long sweepInterval; long sweepTimeout; // Cryo is meant for holding incoming requests in suspended animation, until some unit of work, // executed asynchronously, is completed and ready to deliver payload. Upon revival, the payload // (if any) will be handed over to appropriate actor (origin or bounce target) and further processing // resumes. // // Cryo will not hold onto these requests forever - there is an active sweeper scanning & terminating // requests as necessary. Current version is using a global timeout value (unfortunate). //
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseInternalMessage.java // public interface FuseInternalMessage extends FuseOriginChain { // // FuseMessageContext getContext(); // // long getRequestId(); // // long getTimestamp(); // // FuseInternalMessage timestamp(); // } // // Path: src/main/java/com/sulaco/fuse/config/ConfigSource.java // public interface ConfigSource { // // public void parseLocalConfig(); // // public Config getConfig(); // // public RoutesConfig getRoutesConfig(); // } // // Path: src/main/java/com/sulaco/fuse/config/actor/ActorFactory.java // public interface ActorFactory extends ActorSystemAware, ApplicationContextAware { // // public Optional<ActorRef> getLocalActor(String actorClass); // // public Optional<ActorRef> getLocalActor(String actorClass, String actorName); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, int spinCount); // // public Optional<ActorRef> getLocalActor(String ref, String actorClass, String actorName, int spinCount); // // public Optional<ActorRef> getLocalActorByRef(String ref); // // public Optional<ActorSelection> select(String path); // // public Iterable<ActorRef> getRoutees(String ref, Class<?> clazz, int spinCount); // // // } // Path: src/main/java/com/sulaco/fuse/akka/async/RequestSuspenderImpl.java import akka.actor.ActorSelection; import com.sulaco.fuse.akka.message.FuseInternalMessage; import com.sulaco.fuse.config.ConfigSource; import com.sulaco.fuse.config.actor.ActorFactory; import com.typesafe.config.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; import java.util.NavigableMap; import java.util.Optional; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; package com.sulaco.fuse.akka.async; @Component public class RequestSuspenderImpl implements RequestSuspender { @Autowired ConfigSource configSource; @Autowired ActorFactory actorFactory; long sweepInterval; long sweepTimeout; // Cryo is meant for holding incoming requests in suspended animation, until some unit of work, // executed asynchronously, is completed and ready to deliver payload. Upon revival, the payload // (if any) will be handed over to appropriate actor (origin or bounce target) and further processing // resumes. // // Cryo will not hold onto these requests forever - there is an active sweeper scanning & terminating // requests as necessary. Current version is using a global timeout value (unfortunate). //
NavigableMap<Long, FuseInternalMessage> cryo;
gibffe/fuse
src/main/java/com/sulaco/fuse/akka/actor/RouteFinderActor.java
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessage.java // public interface FuseRequestMessage extends Route { // // long getId(); // // HttpRequest getRequest(); // // String getRequestBody(); // // ChannelHandlerContext getChannelContext(); // // void flush(); // // boolean flushed(); // // public <T> Optional<T> getParam(String name, Class<T> clazz); // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/Route.java // public interface Route { // // public RouteHandler getHandler(); // // public Map<String, String> getParams(); // // public Optional<String> getParam(String name); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/RoutesConfig.java // public interface RoutesConfig { // // public void parse(); // // public Optional<Route> getFuseRoute(String uri); // // public void addEndpoint(ActorRef ref, String httpMethod, String path); // }
import io.netty.handler.codec.http.HttpMethod; import java.util.Optional; import io.netty.handler.codec.http.HttpResponseStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import com.sulaco.fuse.akka.message.FuseRequestMessage; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import com.sulaco.fuse.config.route.Route; import com.sulaco.fuse.config.route.RoutesConfig;
package com.sulaco.fuse.akka.actor; public class RouteFinderActor extends FuseEndpointActor { @Autowired protected RoutesConfig routes; @Override
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessage.java // public interface FuseRequestMessage extends Route { // // long getId(); // // HttpRequest getRequest(); // // String getRequestBody(); // // ChannelHandlerContext getChannelContext(); // // void flush(); // // boolean flushed(); // // public <T> Optional<T> getParam(String name, Class<T> clazz); // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/Route.java // public interface Route { // // public RouteHandler getHandler(); // // public Map<String, String> getParams(); // // public Optional<String> getParam(String name); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/RoutesConfig.java // public interface RoutesConfig { // // public void parse(); // // public Optional<Route> getFuseRoute(String uri); // // public void addEndpoint(ActorRef ref, String httpMethod, String path); // } // Path: src/main/java/com/sulaco/fuse/akka/actor/RouteFinderActor.java import io.netty.handler.codec.http.HttpMethod; import java.util.Optional; import io.netty.handler.codec.http.HttpResponseStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import com.sulaco.fuse.akka.message.FuseRequestMessage; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import com.sulaco.fuse.config.route.Route; import com.sulaco.fuse.config.route.RoutesConfig; package com.sulaco.fuse.akka.actor; public class RouteFinderActor extends FuseEndpointActor { @Autowired protected RoutesConfig routes; @Override
protected void onRequest(final FuseRequestMessage message) {
gibffe/fuse
src/main/java/com/sulaco/fuse/akka/actor/RouteFinderActor.java
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessage.java // public interface FuseRequestMessage extends Route { // // long getId(); // // HttpRequest getRequest(); // // String getRequestBody(); // // ChannelHandlerContext getChannelContext(); // // void flush(); // // boolean flushed(); // // public <T> Optional<T> getParam(String name, Class<T> clazz); // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/Route.java // public interface Route { // // public RouteHandler getHandler(); // // public Map<String, String> getParams(); // // public Optional<String> getParam(String name); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/RoutesConfig.java // public interface RoutesConfig { // // public void parse(); // // public Optional<Route> getFuseRoute(String uri); // // public void addEndpoint(ActorRef ref, String httpMethod, String path); // }
import io.netty.handler.codec.http.HttpMethod; import java.util.Optional; import io.netty.handler.codec.http.HttpResponseStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import com.sulaco.fuse.akka.message.FuseRequestMessage; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import com.sulaco.fuse.config.route.Route; import com.sulaco.fuse.config.route.RoutesConfig;
package com.sulaco.fuse.akka.actor; public class RouteFinderActor extends FuseEndpointActor { @Autowired protected RoutesConfig routes; @Override protected void onRequest(final FuseRequestMessage message) { String uri = message.getRequest().getUri();
// Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessage.java // public interface FuseRequestMessage extends Route { // // long getId(); // // HttpRequest getRequest(); // // String getRequestBody(); // // ChannelHandlerContext getChannelContext(); // // void flush(); // // boolean flushed(); // // public <T> Optional<T> getParam(String name, Class<T> clazz); // // } // // Path: src/main/java/com/sulaco/fuse/akka/message/FuseRequestMessageImpl.java // public class FuseRequestMessageImpl implements FuseRequestMessage { // // long id; // // HttpRequest incomingRequest; // // ChannelHandlerContext channelContext; // // Route route; // // volatile boolean flushed = false; // // public FuseRequestMessageImpl(long id, ChannelHandlerContext context, HttpRequest request) { // this.id = id; // this.channelContext = context; // this.incomingRequest = request; // } // // @Override // public long getId() { // return id; // } // // @Override // public HttpRequest getRequest() { // return incomingRequest; // } // // @Override // public ChannelHandlerContext getChannelContext() { // return channelContext; // } // // @Override // public RouteHandler getHandler() { // return route.getHandler(); // } // // @Override // public Map<String, String> getParams() { // return route.getParams(); // } // // @Override // public Optional<String> getParam(String name) { // return route.getParam(name); // } // // @Override // public <T> Optional<T> getParam(String name, Class<T> clazz) { // Optional<String> param = route.getParam(name); // return param.map(v -> PrimitiveConverters.convert(v, clazz)); // } // // @Override // public String getRequestBody() { // return ((DefaultFullHttpRequest) incomingRequest).content().toString(charset_utf8); // } // // public void setRoute(Route route) { // this.route = route; // } // // @Override // public void flush() { // channelContext.flush(); // flushed = true; // } // // @Override // public boolean flushed() { // return flushed; // } // // private static final Charset charset_utf8 = Charset.forName("UTF-8"); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/Route.java // public interface Route { // // public RouteHandler getHandler(); // // public Map<String, String> getParams(); // // public Optional<String> getParam(String name); // // } // // Path: src/main/java/com/sulaco/fuse/config/route/RoutesConfig.java // public interface RoutesConfig { // // public void parse(); // // public Optional<Route> getFuseRoute(String uri); // // public void addEndpoint(ActorRef ref, String httpMethod, String path); // } // Path: src/main/java/com/sulaco/fuse/akka/actor/RouteFinderActor.java import io.netty.handler.codec.http.HttpMethod; import java.util.Optional; import io.netty.handler.codec.http.HttpResponseStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import com.sulaco.fuse.akka.message.FuseRequestMessage; import com.sulaco.fuse.akka.message.FuseRequestMessageImpl; import com.sulaco.fuse.config.route.Route; import com.sulaco.fuse.config.route.RoutesConfig; package com.sulaco.fuse.akka.actor; public class RouteFinderActor extends FuseEndpointActor { @Autowired protected RoutesConfig routes; @Override protected void onRequest(final FuseRequestMessage message) { String uri = message.getRequest().getUri();
Optional<Route> route = routes.getFuseRoute(uri);