private static Directory getMetaDirectory(File file) { try { Metadata metadata = JpegMetadataReader.readMetadata(file); return metadata.getDirectory(ExifDirectory.class); } catch (JpegProcessingException e) { e.printStackTrace(); } return null; }
private void getAutoGeneratedRules( Metadata metadata, Condition condition, Condition parentCondition, List<Rule> rules) { Set<String> tags = condition.getConditionType().getMetadata().getTags(); if (tags.contains("eventCondition") && !tags.contains("profileCondition")) { try { Map<String, Object> m = new HashMap<>(3); m.put("scope", metadata.getScope()); m.put("condition", condition); m.put("numberOfDays", parentCondition.getParameter("numberOfDays")); String key = CustomObjectMapper.getObjectMapper().writeValueAsString(m); key = "eventTriggered" + getMD5(key); parentCondition.setParameter("generatedPropertyKey", key); Rule rule = rulesService.getRule(key); if (rule == null) { rule = new Rule( new Metadata( metadata.getScope(), key, "Auto generated rule for " + metadata.getName(), "")); rule.setCondition(condition); rule.getMetadata().setHidden(true); final Action action = new Action(); action.setActionType(definitionsService.getActionType("setEventOccurenceCountAction")); action.setParameter("pastEventCondition", parentCondition); rule.setActions(Arrays.asList(action)); rule.setLinkedItems(Arrays.asList(metadata.getId())); rules.add(rule); updateExistingProfilesForPastEventCondition(condition, parentCondition); } else { rule.getLinkedItems().add(metadata.getId()); rules.add(rule); } } catch (JsonProcessingException e) { logger.error(e.getMessage(), e); } } else { Collection<Object> values = new ArrayList<>(condition.getParameterValues().values()); for (Object parameterValue : values) { if (parameterValue instanceof Condition) { getAutoGeneratedRules(metadata, (Condition) parameterValue, condition, rules); } else if (parameterValue instanceof Collection) { for (Object subCondition : (Collection<?>) parameterValue) { if (subCondition instanceof Condition) { getAutoGeneratedRules(metadata, (Condition) subCondition, condition, rules); } } } } } }
private void refreshEndpointMap() { String keyspace = ConfigHelper.getOutputKeyspace(conf); try (Session session = CqlConfigHelper.getOutputCluster(ConfigHelper.getOutputInitialAddress(conf), conf) .connect(keyspace)) { rangeMap = new HashMap<>(); metadata = session.getCluster().getMetadata(); Set<TokenRange> ranges = metadata.getTokenRanges(); for (TokenRange range : ranges) { rangeMap.put(range, metadata.getReplicas(keyspace, range)); } } }
public void updateAutoGeneratedRules(Metadata metadata, Condition condition) { List<Rule> previousRules = persistenceService.query("linkedItems", metadata.getId(), null, Rule.class); List<Rule> rules = new ArrayList<Rule>(); if (condition != null) { getAutoGeneratedRules(metadata, condition, null, rules); } for (Rule rule : rules) { rulesService.setRule(rule); } previousRules.removeAll(rules); clearAutoGeneratedRules(previousRules, metadata.getId()); }
public TokenRange getRange(ByteBuffer key) { Token t = partitioner.getToken(key); com.datastax.driver.core.Token driverToken = metadata.newToken(partitioner.getTokenFactory().toString(t)); for (TokenRange range : rangeMap.keySet()) { if (range.contains(driverToken)) { return range; } } throw new RuntimeException( "Invalid token information returned by describe_ring: " + rangeMap); }
private boolean enableDocumentationGeneration() { return !Metadata.getCurrent().isWarDeployed() && isBasePlugin(); }
@SuppressWarnings("unchecked") private void evaluateOnChangeListener() { if (pluginBean.isReadableProperty(ON_SHUTDOWN)) { onShutdownListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_SHUTDOWN); } if (pluginBean.isReadableProperty(ON_CONFIG_CHANGE)) { onConfigChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CONFIG_CHANGE); } if (pluginBean.isReadableProperty(ON_CHANGE)) { onChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CHANGE); } final boolean warDeployed = Metadata.getCurrent().isWarDeployed(); final boolean reloadEnabled = Environment.getCurrent().isReloadEnabled(); if (!((reloadEnabled || !warDeployed) && onChangeListener != null)) { return; } Object referencedResources = GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, WATCHED_RESOURCES); try { List resourceList = null; if (referencedResources instanceof String) { if (LOG.isDebugEnabled()) { LOG.debug( "Configuring plugin " + this + " to watch resources with pattern: " + referencedResources); } resourceList = new ArrayList(); resourceList.add(referencedResources.toString()); } else if (referencedResources instanceof List) { resourceList = (List) referencedResources; } if (resourceList != null) { List<String> resourceListTmp = new ArrayList<String>(); PluginBuildSettings pluginBuildSettings = GrailsPluginUtils.getPluginBuildSettings(); if (pluginBuildSettings != null) { final Resource[] pluginDirs = pluginBuildSettings.getPluginDirectories(); final Environment env = Environment.getCurrent(); final String baseLocation = env.getReloadLocation(); for (Object ref : resourceList) { String stringRef = ref.toString(); if (!warDeployed) { for (Resource pluginDir : pluginDirs) { if (pluginDir != null) { String pluginResources = getResourcePatternForBaseLocation( pluginDir.getFile().getCanonicalPath(), stringRef); resourceListTmp.add(pluginResources); } } addBaseLocationPattern(resourceListTmp, baseLocation, stringRef); } else { addBaseLocationPattern(resourceListTmp, baseLocation, stringRef); } } watchedResourcePatternReferences = new String[resourceListTmp.size()]; for (int i = 0; i < watchedResourcePatternReferences.length; i++) { String resRef = resourceListTmp.get(i); watchedResourcePatternReferences[i] = resRef; } watchedResourcePatterns = new WatchPatternParser() .getWatchPatterns(Arrays.asList(watchedResourcePatternReferences)); } } } catch (IllegalArgumentException e) { if (GrailsUtil.isDevelopmentEnv()) { LOG.debug( "Cannot load plug-in resource watch list from [" + ArrayUtils.toString(watchedResourcePatternReferences) + "]. This means that the plugin " + this + ", will not be able to auto-reload changes effectively. Try runnng grails upgrade.: " + e.getMessage()); } } catch (IOException e) { if (GrailsUtil.isDevelopmentEnv()) { LOG.debug( "Cannot load plug-in resource watch list from [" + ArrayUtils.toString(watchedResourcePatternReferences) + "]. This means that the plugin " + this + ", will not be able to auto-reload changes effectively. Try runnng grails upgrade.: " + e.getMessage()); } } }