List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:com.vmware.bdd.specpolicy.TemplateClusterSpec.java
private static void createTemplate(Reader fileReader) { Gson gson = new Gson(); templateClusterConfig = gson.fromJson(fileReader, ClusterCreate.class); NodeGroupCreate[] groups = templateClusterConfig.getNodeGroups(); if (groups == null || groups.length == 0) { throw TemplateClusterException.TEMPLATE_NODEGROUPS_UNDEFINED(); }/* w w w. ja v a2 s . c om*/ EnumSet<HadoopRole> allRoles = EnumSet.noneOf(HadoopRole.class); for (NodeGroupCreate group : groups) { List<String> roles = group.getRoles(); if (roles == null || roles.isEmpty()) { throw TemplateClusterException.TEMPLATE_ROLES_EMPTY(group.getName()); } EnumSet<HadoopRole> enumRoles = EnumSet.noneOf(HadoopRole.class); for (String role : roles) { HadoopRole configuredRole = HadoopRole.fromString(role); if (configuredRole == null) { throw ClusterConfigException.UNSUPPORTED_HADOOP_ROLE(role, templateClusterConfig.getDistro()); } enumRoles.add(configuredRole); } GroupType type = GroupType.fromHadoopRole(enumRoles); group.setGroupType(type); templateGroups.put(type, group); allRoles.addAll(enumRoles); } if (!templateGroups.containsKey(GroupType.MASTER_JOBTRACKER_GROUP)) { templateGroups.put(GroupType.MASTER_JOBTRACKER_GROUP, templateGroups.get(GroupType.MASTER_GROUP)); } if (allRoles.size() < HadoopRole.values().length) { throw TemplateClusterException.INCOMPLETE_TEMPLATE_GROUPS(); } }
From source file:org.trancecode.xproc.step.HashStepProcessor.java
@Override protected void execute(final StepInput input, final StepOutput output) { final XdmNode sourceDocument = input.readNode(XProcPorts.SOURCE); final String value = input.getOptionValue(XProcOptions.VALUE); assert value != null; LOG.trace("value = {}", value); final String algorithm = input.getOptionValue(XProcOptions.ALGORITHM); assert algorithm != null; LOG.trace("algorithm = {}", algorithm); final String match = input.getOptionValue(XProcOptions.MATCH); assert match != null; LOG.trace("match = {}", match); final String version = input.getOptionValue(XProcOptions.VERSION); LOG.trace("version = {}", version); final String hashValue; if (StringUtils.equalsIgnoreCase("crc", algorithm)) { if ("32".equals(version) || version == null) { final CRC32 crc32 = new CRC32(); crc32.update(value.getBytes()); hashValue = Long.toHexString(crc32.getValue()); } else {/*w w w .java 2 s .c o m*/ throw XProcExceptions.xc0036(input.getLocation()); } } else if (StringUtils.equalsIgnoreCase("md", algorithm)) { if (version == null || "5".equals(version)) { hashValue = DigestUtils.md5Hex(value); } else { throw XProcExceptions.xc0036(input.getLocation()); } } else if (StringUtils.equalsIgnoreCase("sha", algorithm)) { if (version == null || "1".equals(version)) { hashValue = DigestUtils.shaHex(value); } else if ("256".equals(version)) { hashValue = DigestUtils.sha256Hex(value); } else if ("384".equals(version)) { hashValue = DigestUtils.sha384Hex(value); } else if ("512".equals(version)) { hashValue = DigestUtils.sha512Hex(value); } else { throw XProcExceptions.xc0036(input.getLocation()); } } else { throw XProcExceptions.xc0036(input.getLocation()); } final SaxonProcessorDelegate hashDelegate = new AbstractSaxonProcessorDelegate() { @Override public boolean startDocument(final XdmNode node, final SaxonBuilder builder) { return true; } @Override public void endDocument(final XdmNode node, final SaxonBuilder builder) { } @Override public EnumSet<NextSteps> startElement(final XdmNode element, final SaxonBuilder builder) { builder.text(hashValue); return EnumSet.noneOf(NextSteps.class); } @Override public void endElement(final XdmNode node, final SaxonBuilder builder) { builder.endElement(); } @Override public void attribute(final XdmNode node, final SaxonBuilder builder) { builder.attribute(node.getNodeName(), hashValue); } @Override public void comment(final XdmNode node, final SaxonBuilder builder) { builder.comment(hashValue); } @Override public void processingInstruction(final XdmNode node, final SaxonBuilder builder) { builder.processingInstruction(node.getNodeName().getLocalName(), hashValue); } @Override public void text(final XdmNode node, final SaxonBuilder builder) { builder.text(hashValue); } }; final SaxonProcessor hashProcessor = new SaxonProcessor(input.getPipelineContext().getProcessor(), SaxonProcessorDelegates.forXsltMatchPattern(input.getPipelineContext().getProcessor(), match, input.getStep().getNode(), hashDelegate, new CopyingSaxonProcessorDelegate())); final XdmNode result = hashProcessor.apply(sourceDocument); output.writeNodes(XProcPorts.RESULT, result); }
From source file:org.tinymediamanager.core.movie.tasks.MovieFindMissingTask.java
public HashSet<Path> getBigFilesRecursive(Path folder) { BigFilesRecursive visitor = new BigFilesRecursive(); try {/* w w w .ja va 2s . com*/ Files.walkFileTree(folder, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor); } catch (IOException e) { // can not happen, since we overrided visitFileFailed, which throws no exception ;) } return visitor.fFound; }
From source file:org.apache.bval.cdi.BValExtension.java
private static Set<ExecutableType> convertToRuntimeTypes( final Set<ExecutableType> defaultValidatedExecutableTypes) { final Set<ExecutableType> types = EnumSet.noneOf(ExecutableType.class); for (final ExecutableType type : defaultValidatedExecutableTypes) { if (ExecutableType.NONE == type) { continue; }/*from www.java 2s. c o m*/ if (ExecutableType.ALL == type) { types.add(ExecutableType.CONSTRUCTORS); types.add(ExecutableType.NON_GETTER_METHODS); types.add(ExecutableType.GETTER_METHODS); break; } if (ExecutableType.IMPLICIT == type) { types.add(ExecutableType.CONSTRUCTORS); types.add(ExecutableType.NON_GETTER_METHODS); } else { types.add(type); } } return types; }
From source file:org.abs_models.backend.erlang.ErlangTestDriver.java
/** * Generates Erlang code in target directory, adding a last statement that * prints the value of the `testresult' variable. * * @return a Module Name containing a Main Block * @throws InternalBackendException/*from w w w .j a v a 2s .c om*/ * */ public String genCode(Model model, File targetDir, boolean appendResultprinter) throws IOException, InterruptedException, InternalBackendException { if (model.hasErrors()) { Assert.fail(model.getErrors().getFirstError().getHelpMessage()); } if (model.hasTypeErrors()) { Assert.fail(model.getTypeErrors().getFirstError().getHelpMessage()); } MainBlock mb = model.getMainBlock(); if (mb != null && appendResultprinter) { // We search for this output in the `run' method below mb.addStmt(new ExpressionStmt(new List<>(), new FnApp("ABS.StdLib.println", new List<>(new AddAddExp(new StringLiteral("RES="), new FnApp("ABS.StdLib.toString", new List<>(new VarUse("testresult")))))))); } new ErlangBackend().compile(model, targetDir, // use the following argument for silent compiler: EnumSet.noneOf(ErlangBackend.CompileOptions.class) // use the following argument for verbose compiler output: // EnumSet.of(ErlangBackend.CompileOptions.VERBOSE) ); if (mb == null) return null; else return mb.getModuleDecl().getName(); }
From source file:at.ac.univie.isc.asio.platform.FileSystemConfigStore.java
@Override public Map<String, ByteSource> findAllWithIdentifier(final String identifier) throws DataAccessException { final FindFiles collector = FindFiles.filter(filesWithIdentifier(identifier)); Map<String, ByteSource> found = new HashMap<>(); try {/* ww w . j a v a2 s . c o m*/ log.debug(Scope.SYSTEM.marker(), "searching items with identifier <{}>", identifier); lock(); Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), 1, collector); for (final Path path : collector.found()) { log.debug(Scope.SYSTEM.marker(), "found <{}>", path); final Path fileName = path.getFileName(); final String[] parts = fileName.toString().split("\\#\\#"); found.put(parts[0], asByteSource(path.toFile())); } } catch (IOException e) { throw new FileSystemAccessFailure("finding items of type <" + identifier + "> failed", e); } finally { lock.unlock(); } return ImmutableMap.copyOf(found); }
From source file:net.sf.gazpachoquest.services.core.impl.AbstractLocalizedPersistenceService.java
@Override public Set<Language> translationsSupported(final Integer entityId) { L entity = super.repository.findOne(entityId); if (entity == null) { return null; }/*from w w w.ja v a2 s .com*/ TR translationExample = translationBuilder.translatedEntityId(entityId).build(); List<TR> supportedLanguages = translationRepository.findByExample(translationExample, new SearchParameters()); List<Language> list = new ArrayList<>(); for (TR tr : supportedLanguages) { list.add(tr.getLanguage()); } return list.isEmpty() ? EnumSet.noneOf(Language.class) : EnumSet.copyOf(list); }
From source file:org.apache.syncope.client.console.panels.ConnectorModal.java
public ConnectorModal(final ModalWindow window, final PageReference pageRef, final ConnInstanceTO connInstanceTO) { super(window, pageRef); this.add(new Label("new", connInstanceTO.getKey() == 0 ? new ResourceModel("new") : new Model<>(StringUtils.EMPTY))); this.add(new Label("key", connInstanceTO.getKey() == 0 ? StringUtils.EMPTY : connInstanceTO.getKey())); // general data setup selectedCapabilities = new ArrayList<>( connInstanceTO.getKey() == 0 ? EnumSet.noneOf(ConnectorCapability.class) : connInstanceTO.getCapabilities()); mapConnBundleTOs = new HashMap<>(); for (ConnBundleTO connBundleTO : connectorRestClient.getAllBundles()) { // by location if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) { mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>()); }// ww w .j av a 2 s .co m final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs .get(connBundleTO.getLocation()); // by name if (!byLocation.containsKey(connBundleTO.getBundleName())) { byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>()); } final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName()); // by version if (!byName.containsKey(connBundleTO.getVersion())) { byName.put(connBundleTO.getVersion(), connBundleTO); } } bundleTO = getSelectedBundleTO(connInstanceTO); properties = fillProperties(bundleTO, connInstanceTO); // form - first tab final Form<ConnInstanceTO> connectorForm = new Form<>(FORM); connectorForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorForm.setOutputMarkupId(true); add(connectorForm); propertiesContainer = new WebMarkupContainer("container"); propertiesContainer.setOutputMarkupId(true); connectorForm.add(propertiesContainer); final Form<ConnInstanceTO> connectorPropForm = new Form<>("connectorPropForm"); connectorPropForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorPropForm.setOutputMarkupId(true); propertiesContainer.add(connectorPropForm); final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name", new PropertyModel<String>(connInstanceTO, "displayName")); displayName.setOutputMarkupId(true); displayName.addRequiredLabel(); connectorForm.add(displayName); final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<>("location", "location", new Model<>(bundleTO == null ? null : bundleTO.getLocation())); ((DropDownChoice<String>) location.getField()).setNullValid(true); location.setStyleSheet("long_dynamicsize"); location.setChoices(new ArrayList<>(mapConnBundleTOs.keySet())); location.setRequired(true); location.addRequiredLabel(); location.setOutputMarkupId(true); location.setEnabled(connInstanceTO.getKey() == 0); location.getField().setOutputMarkupId(true); connectorForm.add(location); final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<>("connectorName", "connectorName", new Model<>(bundleTO == null ? null : bundleTO.getBundleName())); ((DropDownChoice<String>) connectorName.getField()).setNullValid(true); connectorName.setStyleSheet("long_dynamicsize"); connectorName.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet())); connectorName.setRequired(true); connectorName.addRequiredLabel(); connectorName.setEnabled(connInstanceTO.getLocation() != null); connectorName.setOutputMarkupId(true); connectorName.setEnabled(connInstanceTO.getKey() == 0); connectorName.getField().setOutputMarkupId(true); connectorForm.add(connectorName); final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version", new Model<>(bundleTO == null ? null : bundleTO.getVersion())); version.setStyleSheet("long_dynamicsize"); version.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()) .get(connInstanceTO.getBundleName()).keySet())); version.setRequired(true); version.addRequiredLabel(); version.setEnabled(connInstanceTO.getBundleName() != null); version.setOutputMarkupId(true); version.addRequiredLabel(); version.getField().setOutputMarkupId(true); connectorForm.add(version); final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<>("connRequestTimeout", "connRequestTimeout", Integer.class, new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null); connRequestTimeout.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(connRequestTimeout); if (connInstanceTO.getPoolConf() == null) { connInstanceTO.setPoolConf(new ConnPoolConfTO()); } final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<>("poolMaxObjects", "poolMaxObjects", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null); poolMaxObjects.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxObjects); final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<>("poolMinIdle", "poolMinIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null); poolMinIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMinIdle); final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<>("poolMaxIdle", "poolMaxIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null); poolMaxIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxIdle); final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<>("poolMaxWait", "poolMaxWait", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null); poolMaxWait.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMaxWait); final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<>("poolMinEvictableIdleTime", "poolMinEvictableIdleTime", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null); poolMinEvictableIdleTime.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMinEvictableIdleTime); // form - first tab - onchange() location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) location.getField()).setNullValid(false); connInstanceTO.setLocation(location.getModelObject()); target.add(location); connectorName.setChoices(new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()).keySet())); connectorName.setEnabled(true); connectorName.getField().setModelValue(null); target.add(connectorName); version.setChoices(new ArrayList<String>()); version.getField().setModelValue(null); version.setEnabled(false); target.add(version); properties.clear(); target.add(propertiesContainer); } }); connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) connectorName.getField()).setNullValid(false); connInstanceTO.setBundleName(connectorName.getModelObject()); target.add(connectorName); List<String> versions = new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()) .get(connectorName.getModelObject()).keySet()); version.setChoices(versions); version.setEnabled(true); if (versions.size() == 1) { selectVersion(target, connInstanceTO, version, versions.get(0)); version.getField().setModelObject(versions.get(0)); } else { version.getField().setModelValue(null); properties.clear(); target.add(propertiesContainer); } target.add(version); } }); version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { selectVersion(target, connInstanceTO, version, version.getModelObject()); } }); // form - second tab (properties) final ListView<ConnConfProperty> connPropView = new ConnConfPropertyListView("connectorProperties", new PropertyModel<List<ConnConfProperty>>(this, "properties"), true, connInstanceTO.getConfiguration()); connPropView.setOutputMarkupId(true); connectorPropForm.add(connPropView); final AjaxButton check = new IndicatingAjaxButton("check", new ResourceModel("check")) { private static final long serialVersionUID = -7978723352517770644L; @Override public void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); // ensure that connector bundle information is in sync conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.setConnectorName(bundleTO.getConnectorName()); if (connectorRestClient.check(conn)) { info(getString("success_connection")); } else { error(getString("error_connection")); } feedbackPanel.refresh(target); } }; connectorPropForm.add(check); // form - third tab (capabilities) final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<ConnectorCapability> load() { return Arrays.asList(ConnectorCapability.values()); } }; CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<>( "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"), capabilities); capabilitiesPalette.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { } }); connectorForm.add(capabilitiesPalette); // form - submit / cancel buttons final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<>(getString(SUBMIT))) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); conn.setConnectorName(bundleTO.getConnectorName()); conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.getConfiguration().clear(); conn.getConfiguration().addAll(connPropView.getModelObject()); // Set the model object's capabilities to capabilitiesPalette's converted Set conn.getCapabilities().clear(); conn.getCapabilities() .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class) : EnumSet.copyOf(selectedCapabilities)); // Reset pool configuration if all fields are null if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null && conn.getPoolConf().getMinIdle() == null) { conn.setPoolConf(null); } try { if (connInstanceTO.getKey() == 0) { connectorRestClient.create(conn); } else { connectorRestClient.update(conn); } ((BasePage) pageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); ((BasePage) pageRef.getPage()).setModalResult(false); LOG.error("While creating or updating connector {}", conn, e); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; String entitlements = connInstanceTO.getKey() == 0 ? Entitlement.CONNECTOR_CREATE : Entitlement.CONNECTOR_UPDATE; MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, entitlements); connectorForm.add(submit); final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); connectorForm.add(cancel); }
From source file:org.apache.syncope.client.console.pages.ConnectorModalPage.java
public ConnectorModalPage(final PageReference pageRef, final ModalWindow window, final ConnInstanceTO connInstanceTO) { super();// w ww .ja v a 2s .c o m this.add(new Label("new", connInstanceTO.getKey() == 0 ? new ResourceModel("new") : new Model<>(StringUtils.EMPTY))); this.add(new Label("key", connInstanceTO.getKey() == 0 ? StringUtils.EMPTY : connInstanceTO.getKey())); // general data setup selectedCapabilities = new ArrayList<>( connInstanceTO.getKey() == 0 ? EnumSet.noneOf(ConnectorCapability.class) : connInstanceTO.getCapabilities()); mapConnBundleTOs = new HashMap<>(); for (ConnBundleTO connBundleTO : restClient.getAllBundles()) { // by location if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) { mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>()); } final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs .get(connBundleTO.getLocation()); // by name if (!byLocation.containsKey(connBundleTO.getBundleName())) { byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>()); } final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName()); // by version if (!byName.containsKey(connBundleTO.getVersion())) { byName.put(connBundleTO.getVersion(), connBundleTO); } } bundleTO = getSelectedBundleTO(connInstanceTO); properties = fillProperties(bundleTO, connInstanceTO); // form - first tab final Form<ConnInstanceTO> connectorForm = new Form<>(FORM); connectorForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorForm.setOutputMarkupId(true); add(connectorForm); propertiesContainer = new WebMarkupContainer("container"); propertiesContainer.setOutputMarkupId(true); connectorForm.add(propertiesContainer); final Form<ConnInstanceTO> connectorPropForm = new Form<>("connectorPropForm"); connectorPropForm.setModel(new CompoundPropertyModel<>(connInstanceTO)); connectorPropForm.setOutputMarkupId(true); propertiesContainer.add(connectorPropForm); final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name", new PropertyModel<String>(connInstanceTO, "displayName")); displayName.setOutputMarkupId(true); displayName.addRequiredLabel(); connectorForm.add(displayName); final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<>("location", "location", new Model<>(bundleTO == null ? null : bundleTO.getLocation())); ((DropDownChoice<String>) location.getField()).setNullValid(true); location.setStyleSheet("long_dynamicsize"); location.setChoices(new ArrayList<>(mapConnBundleTOs.keySet())); location.setRequired(true); location.addRequiredLabel(); location.setOutputMarkupId(true); location.setEnabled(connInstanceTO.getKey() == 0); location.getField().setOutputMarkupId(true); connectorForm.add(location); final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<>("connectorName", "connectorName", new Model<>(bundleTO == null ? null : bundleTO.getBundleName())); ((DropDownChoice<String>) connectorName.getField()).setNullValid(true); connectorName.setStyleSheet("long_dynamicsize"); connectorName.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet())); connectorName.setRequired(true); connectorName.addRequiredLabel(); connectorName.setEnabled(connInstanceTO.getLocation() != null); connectorName.setOutputMarkupId(true); connectorName.setEnabled(connInstanceTO.getKey() == 0); connectorName.getField().setOutputMarkupId(true); connectorForm.add(connectorName); final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<>("version", "version", new Model<>(bundleTO == null ? null : bundleTO.getVersion())); version.setStyleSheet("long_dynamicsize"); version.setChoices(bundleTO == null ? new ArrayList<String>() : new ArrayList<>(mapConnBundleTOs.get(connInstanceTO.getLocation()) .get(connInstanceTO.getBundleName()).keySet())); version.setRequired(true); version.addRequiredLabel(); version.setEnabled(connInstanceTO.getBundleName() != null); version.setOutputMarkupId(true); version.addRequiredLabel(); version.getField().setOutputMarkupId(true); connectorForm.add(version); final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<>("connRequestTimeout", "connRequestTimeout", Integer.class, new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null); connRequestTimeout.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(connRequestTimeout); if (connInstanceTO.getPoolConf() == null) { connInstanceTO.setPoolConf(new ConnPoolConfTO()); } final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<>("poolMaxObjects", "poolMaxObjects", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null); poolMaxObjects.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxObjects); final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<>("poolMinIdle", "poolMinIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null); poolMinIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMinIdle); final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<>("poolMaxIdle", "poolMaxIdle", Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null); poolMaxIdle.getField().add(new RangeValidator<>(0, Integer.MAX_VALUE)); connectorForm.add(poolMaxIdle); final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<>("poolMaxWait", "poolMaxWait", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null); poolMaxWait.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMaxWait); final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<>("poolMinEvictableIdleTime", "poolMinEvictableIdleTime", Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null); poolMinEvictableIdleTime.getField().add(new RangeValidator<>(0L, Long.MAX_VALUE)); connectorForm.add(poolMinEvictableIdleTime); // form - first tab - onchange() location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) location.getField()).setNullValid(false); connInstanceTO.setLocation(location.getModelObject()); target.add(location); connectorName.setChoices(new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()).keySet())); connectorName.setEnabled(true); connectorName.getField().setModelValue(null); target.add(connectorName); version.setChoices(new ArrayList<String>()); version.getField().setModelValue(null); version.setEnabled(false); target.add(version); properties.clear(); target.add(propertiesContainer); } }); connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { ((DropDownChoice<String>) connectorName.getField()).setNullValid(false); connInstanceTO.setBundleName(connectorName.getModelObject()); target.add(connectorName); List<String> versions = new ArrayList<>(mapConnBundleTOs.get(location.getModelObject()) .get(connectorName.getModelObject()).keySet()); version.setChoices(versions); version.setEnabled(true); if (versions.size() == 1) { selectVersion(target, connInstanceTO, version, versions.get(0)); version.getField().setModelObject(versions.get(0)); } else { version.getField().setModelValue(null); properties.clear(); target.add(propertiesContainer); } target.add(version); } }); version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { selectVersion(target, connInstanceTO, version, version.getModelObject()); } }); // form - second tab (properties) final ListView<ConnConfProperty> connPropView = new ConnConfPropertyListView("connectorProperties", new PropertyModel<List<ConnConfProperty>>(this, "properties"), true, connInstanceTO.getConfiguration()); connPropView.setOutputMarkupId(true); connectorPropForm.add(connPropView); final AjaxButton check = new IndicatingAjaxButton("check", new ResourceModel("check")) { private static final long serialVersionUID = -7978723352517770644L; @Override public void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); // ensure that connector bundle information is in sync conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.setConnectorName(bundleTO.getConnectorName()); if (restClient.check(conn)) { info(getString("success_connection")); } else { error(getString("error_connection")); } feedbackPanel.refresh(target); } }; connectorPropForm.add(check); // form - third tab (capabilities) final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() { private static final long serialVersionUID = 5275935387613157437L; @Override protected List<ConnectorCapability> load() { return Arrays.asList(ConnectorCapability.values()); } }; CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<>( "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"), capabilities); capabilitiesPalette.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(AjaxRequestTarget target) { } }); connectorForm.add(capabilitiesPalette); // form - submit / cancel buttons final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<>(getString(SUBMIT))) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject(); conn.setConnectorName(bundleTO.getConnectorName()); conn.setBundleName(bundleTO.getBundleName()); conn.setVersion(bundleTO.getVersion()); conn.getConfiguration().clear(); conn.getConfiguration().addAll(connPropView.getModelObject()); // Set the model object's capabilities to capabilitiesPalette's converted Set conn.getCapabilities().clear(); conn.getCapabilities() .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class) : EnumSet.copyOf(selectedCapabilities)); // Reset pool configuration if all fields are null if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null && conn.getPoolConf().getMinIdle() == null) { conn.setPoolConf(null); } try { if (connInstanceTO.getKey() == 0) { restClient.create(conn); } else { restClient.update(conn); } ((Resources) pageRef.getPage()).setModalResult(true); window.close(target); } catch (SyncopeClientException e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); feedbackPanel.refresh(target); ((Resources) pageRef.getPage()).setModalResult(false); LOG.error("While creating or updating connector {}", conn, e); } } @Override protected void onError(final AjaxRequestTarget target, final Form<?> form) { feedbackPanel.refresh(target); } }; String roles = connInstanceTO.getKey() == 0 ? xmlRolesReader.getEntitlement("Connectors", "create") : xmlRolesReader.getEntitlement("Connectors", "update"); MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles); connectorForm.add(submit); final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { private static final long serialVersionUID = -958724007591692537L; @Override protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { window.close(target); } }; cancel.setDefaultFormProcessing(false); connectorForm.add(cancel); }
From source file:com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory.java
private ImmutableSet<ResultAttribute> initResultAttributesToWriteAsTags(List<String> resultTags) { EnumSet<ResultAttribute> resultAttributes = EnumSet.noneOf(ResultAttribute.class); if (resultTags != null) { for (String resultTag : resultTags) { resultAttributes.add(ResultAttribute.fromAttribute(resultTag)); }/*from w w w . j a v a 2 s .c o m*/ } else { resultAttributes = EnumSet.allOf(ResultAttribute.class); } ImmutableSet<ResultAttribute> result = immutableEnumSet(resultAttributes); LOG.debug("Result Tags to write set to: {}", result); return result; }