private String getScopeStringRep() { try { return ScopeGenerator.generateStringRep(scope); } catch (CouldNotPerformException ex) { return "?"; } }
/** * Method prints a class instance representation. * * @return the class string representation. */ @Override public String toString() { try { return getClass().getSimpleName() + "[scope:" + ScopeGenerator.generateStringRep(scope) + "]"; } catch (CouldNotPerformException ex) { return getClass().getSimpleName() + "[scope:?]"; } }
@Override public int compare(UnitConfig o1, UnitConfig o2) { try { return ScopeGenerator.generateStringRep(o1.getScope()).compareTo(ScopeGenerator.generateStringRep(o2.getScope())); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not sort scope!", ex, System.err); return 0; } } });
private void scopeCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scopeCancelButtonActionPerformed try { scopeTextField.setText(ScopeGenerator.generateStringRep(unitConfigObservable.getValue().getScope())); } catch (CouldNotPerformException | NullPointerException ex) { scopeTextField.setText(""); } updateButtonStates(); }//GEN-LAST:event_scopeCancelButtonActionPerformed
public void setUnitRemote(final Scope scope) throws CouldNotPerformException, InterruptedException { try { logger.info("Setup unit remote: " + ScopeGenerator.generateStringRep(scope)); RS remote = (RS) Units.getUnitByScope(scope, false); setRemoteService(remote); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not setup unit remote config!", ex); } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, Builder> entry, ProtoBufMessageMap<String, UnitConfig, Builder> entryMap, ProtoBufRegistry<String, UnitConfig, Builder> registry) throws CouldNotPerformException, EntryModification { final UnitConfig.Builder unitConfig = entry.getMessage().toBuilder(); for (final String alias : unitConfig.getAliasList()) { if (!aliasUnitIdMap.containsKey(alias.toLowerCase())) { aliasUnitIdMap.put(alias.toLowerCase(), unitConfig.getId()); } else { // if already known check if this unit is owning the alias otherwise throw invalid state if (!aliasUnitIdMap.get(alias.toLowerCase()).equals(unitConfig.getId())) { throw new RejectedException("Alias[" + alias.toLowerCase() + "] of Unit[" + ScopeGenerator.generateStringRep(unitConfig.getScope()) + ", " + unitConfig.getId() + "] is already used by Unit[" + aliasUnitIdMap.get(alias.toLowerCase()) + "]"); } } } }
public static String generateStringRep(final Scope scope) throws CouldNotPerformException { try { if (scope == null) { throw new NotAvailableException("scope"); } return generateStringRep(scope.getComponents()); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not generate scope string representation!", ex); } }
public static String generateStringRep(final ScopeType.Scope scope) throws CouldNotPerformException { try { if (scope == null) { throw new NotAvailableException("scope"); } return generateStringRep(scope.getComponentList()); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not generate scope string representation!", ex); } }
@RPCMethod default public String getUnitScopeById(final String id) throws CouldNotPerformException { return ScopeGenerator.generateStringRep(getUnitConfigById(id).getScope()); }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig locationConfig = entry.getMessage(); ScopeType.Scope newScope = ScopeGenerator.generateLocationScope(locationConfig, entryMap); // verify and update scope if (!ScopeGenerator.generateStringRep(locationConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { entry.setMessage(locationConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } } }
@RPCMethod default public String getUnitScopeByAlias(final String alias) throws CouldNotPerformException { return ScopeGenerator.generateStringRep(getUnitConfigByAlias(alias).getScope()); }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig authorizationGroupUnitConfig = entry.getMessage(); if (!authorizationGroupUnitConfig.hasLabel() || authorizationGroupUnitConfig.getLabel().isEmpty()) { throw new NotAvailableException("user.label"); } ScopeType.Scope newScope = ScopeGenerator.generateAuthorizationGroupScope(authorizationGroupUnitConfig); // verify and update scope if (!ScopeGenerator.generateStringRep(authorizationGroupUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { entry.setMessage(authorizationGroupUnitConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig connectionUnitConfig = entry.getMessage(); Scope newScope = ScopeGenerator.generateConnectionScope(connectionUnitConfig, locationRegistry.getMessage(connectionUnitConfig.getPlacementConfig().getLocationId())); // verify and update scope if (!ScopeGenerator.generateStringRep(connectionUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { entry.setMessage(connectionUnitConfig.toBuilder().setScope(newScope)); throw new EntryModification(entry, this); } } }
public static rsb.Scope transform(final ScopeType.Scope scope) throws CouldNotTransformException { try { if (scope == null) { throw new NotAvailableException("scope"); } return new Scope(ScopeGenerator.generateStringRep(scope.getComponentList())); } catch (Exception ex) { throw new CouldNotTransformException(scope, rsb.Scope.class, ex); } }
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig userUnitConfig = entry.getMessage(); if (!userUnitConfig.getUserConfig().hasUserName() || userUnitConfig.getUserConfig().getUserName().isEmpty()) { throw new NotAvailableException("user.userName"); } ScopeType.Scope newScope = ScopeGenerator.generateUserScope(userUnitConfig); // verify and update scope if (!ScopeGenerator.generateStringRep(userUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) { throw new EntryModification(entry.setMessage(userUnitConfig.toBuilder().setScope(newScope)), this); } } }
public static Class<? extends AbstractUnitController> transform(final UnitConfig unitConfig) throws CouldNotTransformException { String className = AbstractUnitController.class.getPackage().getName() + "." + StringProcessor.transformUpperCaseToCamelCase(unitConfig.getType().name()) + "Controller"; try { return (Class<? extends AbstractUnitController>) Class.forName(className); } catch (ClassNotFoundException ex) { try { throw new CouldNotTransformException(ScopeGenerator.generateStringRep(unitConfig.getScope()), AbstractUnitController.class, new NotAvailableException("Class", ex)); } catch (CouldNotPerformException ex1) { throw new CouldNotTransformException(unitConfig.getLabel(), AbstractUnitController.class, new NotAvailableException("Class", ex)); } } } }
@Override public Void call() throws Exception { try { scopeTextField.setForeground(Color.BLACK); Scope scope = ScopeTransformer.transform(new rsb.Scope(scopeTextField.getText().toLowerCase())); unitConfigObservable.notifyObservers(Registries.getUnitRegistry().getUnitConfigByScope(scope)); scopeTextField.setText(ScopeGenerator.generateStringRep(unitConfigObservable.getValue().getScope())); } catch (CouldNotPerformException ex) { scopeTextField.setForeground(Color.RED); statusPanel.setError(ExceptionPrinter.printHistoryAndReturnThrowable(ex, logger)); } return null; } }));
@Override public UnitConfig getUnitConfigByScope(ScopeType.Scope scope) throws CouldNotPerformException { if (scope == null) { throw new NotAvailableException("scope"); } validateData(); for (UnitConfig unitConfig : getUnitConfigs()) { if (unitConfig.getScope().equals(scope)) { return unitConfig; } } throw new NotAvailableException("No unit config available for given Scope[" + ScopeGenerator.generateStringRep(scope) + "]!"); }
public static void printUnit(final UnitConfig unitConfig, final int maxAliasLength, final int maxUnitLabelLength, final int maxLocationUnitLabelLength, final int maxScopeLength) throws InterruptedException, CouldNotPerformException { System.out.println(unitConfig.getId() + " " + "[ " + StringProcessor.fillWithSpaces(generateStringRep(unitConfig.getAliasList()), maxAliasLength) + " ]" + " " + StringProcessor.fillWithSpaces(unitConfig.getLabel(), maxUnitLabelLength, StringProcessor.Alignment.RIGHT) + " @ " + StringProcessor.fillWithSpaces(getLocationLabel(unitConfig), maxLocationUnitLabelLength) + " " + "[ " + StringProcessor.fillWithSpaces(ScopeGenerator.generateStringRep(unitConfig.getScope()), maxScopeLength) + " ]" ); }
private void verifyUnitConfig(final UnitConfig unitConfig) throws VerificationFailedException { if (!unitConfig.getEnablingState().getValue().equals(EnablingStateType.EnablingState.State.ENABLED)) { try { throw new VerificationFailedException("Referred Unit[" + ScopeGenerator.generateStringRep(unitConfig.getScope()) + "] is disabled!"); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, LOGGER, LogLevel.WARN); throw new VerificationFailedException("Referred Unit[" + unitConfig.getLabel() + "] is disabled!"); } } }