@Override protected List<DataSourceField> addDataSourceFields() { List<DataSourceField> fields = super.addDataSourceFields(); DataSourceField idDataField = new DataSourceIntegerField("id", MSG.common_title_id(), 50); idDataField.setPrimaryKey(true); idDataField.setCanEdit(false); fields.add(idDataField); DataSourceTextField nameDataField = new DataSourceTextField(NAME.propertyName(), NAME.title(), 200); nameDataField.setCanEdit(false); fields.add(nameDataField); DataSourceTextField descriptionDataField = new DataSourceTextField(DESCRIPTION.propertyName(), DESCRIPTION.title()); descriptionDataField.setCanEdit(false); fields.add(descriptionDataField); DataSourceTextField typeNameDataField = new DataSourceTextField(TYPE.propertyName(), TYPE.title()); fields.add(typeNameDataField); DataSourceTextField pluginNameDataField = new DataSourceTextField(PLUGIN.propertyName(), PLUGIN.title()); fields.add(pluginNameDataField); DataSourceTextField categoryDataField = new DataSourceTextField(CATEGORY.propertyName(), CATEGORY.title()); fields.add(categoryDataField); return fields; }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { String operationName = NAME.resolveModelAttribute(context, operation).asString(); boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean(); final DescribedOp describedOp = getDescribedOp(context, operationName, operation, !accessControl); if (describedOp == null || (context.getProcessType() == ProcessType.DOMAIN_SERVER && !describedOp.flags.contains(OperationEntry.Flag.RUNTIME_ONLY))) { throw new OperationFailedException( ControllerLogger.ROOT_LOGGER.operationNotRegistered( operationName, context.getCurrentAddress())); } else { ModelNode result = describedOp.getDescription(); if (accessControl) { final PathAddress address = context.getCurrentAddress(); ModelNode operationToCheck = Util.createOperation(operationName, address); operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS)); AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck); result .get(ACCESS_CONTROL.getName(), EXECUTE) .set(authorizationResult.getDecision() == Decision.PERMIT); } context.getResult().set(result); } }
@Override public ListGridRecord copyValues(ResourceGroupComposite from) { ListGridRecord record = new ListGridRecord(); record.setAttribute("group", from); record.setAttribute("id", from.getResourceGroup().getId()); record.setAttribute(NAME.propertyName(), from.getResourceGroup().getName()); record.setAttribute(DESCRIPTION.propertyName(), from.getResourceGroup().getDescription()); record.setAttribute(CATEGORY.propertyName(), from.getResourceGroup().getGroupCategory().name()); record.setAttribute("explicitCount", String.valueOf(from.getExplicitCount())); record.setAttribute("explicitDown", String.valueOf(from.getExplicitDown())); record.setAttribute("explicitDisabled", String.valueOf(from.getExplicitDisabled())); record.setAttribute("implicitCount", String.valueOf(from.getImplicitCount())); record.setAttribute("implicitDown", String.valueOf(from.getImplicitDown())); record.setAttribute("implicitDisabled", String.valueOf(from.getImplicitDisabled())); record.setAttribute(AVAIL_CHILDREN.propertyName(), getExplicitFormatted(from)); record.setAttribute(AVAIL_DESCENDANTS.propertyName(), getImplicitFormatted(from)); if (from.getResourceGroup().getResourceType() != null) { record.setAttribute("resourceType", from.getResourceGroup().getResourceType()); record.setAttribute(TYPE.propertyName(), from.getResourceGroup().getResourceType().getName()); record.setAttribute( PLUGIN.propertyName(), from.getResourceGroup().getResourceType().getPlugin()); } return record; }
@Override public boolean matches(final String page, final String parameters) { final String pageId = getPageId(parameters); return NAME.equals(page) && (StringUtils.isEmpty(parameters) || parameters.equals(pageId) || parameters.contains(PageMode.OVERVIEW.toString())); }
private MapSqlParameterSource getParametersMap(Malfunction malfunction) { MapSqlParameterSource parameterSource = new MapSqlParameterSource(); parameterSource.addValue(MALFUNCTION_ID.getValue(), malfunction.getMalfunctionId()); parameterSource.addValue(NAME.getValue(), malfunction.getName()); parameterSource.addValue(AUTO.getValue(), malfunction.getAuto()); parameterSource.addValue(DESCRIPTION.getValue(), malfunction.getDescription()); parameterSource.addValue(APPLICATION_ID.getValue(), malfunction.getApplicationId()); return parameterSource; }
@Override public void updateMalfunction(Malfunction malfunction) { LOGGER.info("DAO:Update malfunction by id=" + malfunction.getMalfunctionId().toString()); HashMap<String, Object> hashMap = new HashMap<String, Object>(); hashMap.put(MALFUNCTION_ID.getValue(), malfunction.getMalfunctionId()); hashMap.put(NAME.getValue(), malfunction.getName()); hashMap.put(AUTO.getValue(), malfunction.getAuto()); hashMap.put(DESCRIPTION.getValue(), malfunction.getDescription()); namedParameterJdbcTemplate.update(updateMalfunctionById, hashMap); }
static { Map<QName, Attribute> attributesMap = new HashMap<QName, Attribute>(); attributesMap.put(new QName(GROUP_ID.getLocalName()), GROUP_ID); attributesMap.put(new QName(ARTIFACT_ID.getLocalName()), ARTIFACT_ID); attributesMap.put(new QName(CLASSIFIER.getLocalName()), CLASSIFIER); attributesMap.put(new QName(EXTENSION.getLocalName()), EXTENSION); attributesMap.put(new QName(VERSION.getLocalName()), VERSION); attributesMap.put(new QName(NAME.getLocalName()), NAME); attributes = attributesMap; }
public static LayerPageLink create(String name, String id, LayerInfoModels models) { if (name.equals(WORKSPACE.getName())) { return new WorkspaceLink(id, models); } else if (name.equals(STORE.getName())) { return new StoreLink(id, models); } else if (name.equals(NAME.getName())) { return new LayerLink(id, models); } throw new IllegalArgumentException("Don't know a property named " + name); }
public Project() { super(); dbObject.put("sizeFact", new BasicDBObject()); dbObject.put("activityFact", new BasicDBObject()); dbObject.put("vcsRepositories", new BasicDBList()); super.setSuperTypes("com.googlecode.pongo.tests.ossmeter.model.NamedElement"); NAME.setOwningType("com.googlecode.pongo.tests.ossmeter.model.Project"); DESCRIPTION.setOwningType("com.googlecode.pongo.tests.ossmeter.model.Project"); YEAR.setOwningType("com.googlecode.pongo.tests.ossmeter.model.Project"); ACTIVE.setOwningType("com.googlecode.pongo.tests.ossmeter.model.Project"); }
@Override public void parse( final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list) throws XMLStreamException { if (getXmlWrapperElement() != null) { if (reader.getLocalName().equals(getXmlWrapperElement())) { if (reader.hasNext()) { if (reader.nextTag() == END_ELEMENT) { return; } } } else { throw ParseUtils.unexpectedElement(reader); } } boolean wildcard = getPathElement().isWildcard(); String name = null; ModelNode op = Util.createAddOperation(); Map<String, AttributeDefinition> attributes = getAttributeMap(); for (int i = 0; i < reader.getAttributeCount(); i++) { String attributeName = reader.getAttributeLocalName(i); String value = reader.getAttributeValue(i); if (wildcard && NAME.equals(attributeName)) { name = value; } else if (attributes.containsKey(attributeName)) { AttributeDefinition def = attributes.get(attributeName); if (def instanceof SimpleAttributeDefinition) { ((SimpleAttributeDefinition) def).parseAndSetParameter(value, op, reader); } else if (def instanceof StringListAttributeDefinition) { ((StringListAttributeDefinition) def).parseAndSetParameter(value, op, reader); } else { throw new IllegalArgumentException("we should know how to handle " + def); } } else { throw ParseUtils.unexpectedAttribute(reader, i); } } if (wildcard && name == null) { throw MESSAGES.missingRequiredAttributes(new StringBuilder(NAME), reader.getLocation()); } PathElement path = wildcard ? PathElement.pathElement(getPathElement().getKey(), name) : getPathElement(); PathAddress address = parentAddress.append(path); op.get(ADDRESS).set(address.toModelNode()); list.add(op); parseChildren(reader, address, list); if (getXmlWrapperElement() != null) { ParseUtils.requireNoContent(reader); } }
public static PropertyDataTypes getTypeByTypeNum(int typeNum) { if (STRING.getTypeNum() == typeNum) return STRING; else if (BINARY.getTypeNum() == typeNum) return BINARY; else if (LONG.getTypeNum() == typeNum) return LONG; else if (DOUBLE.getTypeNum() == typeNum) return DOUBLE; else if (DATE.getTypeNum() == typeNum) return DATE; else if (BOOLEAN.getTypeNum() == typeNum) return BOOLEAN; else if (NAME.getTypeNum() == typeNum) return NAME; else if (PATH.getTypeNum() == typeNum) return PATH; else if (REFERENCE.getTypeNum() == typeNum) return REFERENCE; else if (WEAKREFERENCE.getTypeNum() == typeNum) return WEAKREFERENCE; else if (URI.getTypeNum() == typeNum) return URI; else if (DECIMAL.getTypeNum() == typeNum) return DECIMAL; else return UNDEFINED; }
@Override protected ResourceGroupCriteria getFetchCriteria(final DSRequest request) { ResourceGroupCriteria criteria = new ResourceGroupCriteria(); criteria.addFilterId(getFilter(request, "id", Integer.class)); criteria.addFilterName(getFilter(request, NAME.propertyName(), String.class)); criteria.addFilterGroupCategory( getFilter(request, CATEGORY.propertyName(), GroupCategory.class)); criteria.addFilterDownMemberCount(getFilter(request, "downMemberCount", Long.class)); criteria.addFilterExplicitResourceIds(getFilter(request, "explicitResourceId", Integer.class)); criteria.addFilterGroupDefinitionId(getFilter(request, "groupDefinitionId", Integer.class)); criteria.setSearchExpression(getFilter(request, "search", String.class)); criteria.addFilterIds(getArrayFilter(request, FILTER_GROUP_IDS, Integer.class)); return criteria; }
/** * Introduce a new declaration which will mask any declaration with the same name in the {@link * #getParentContext} context. */ public VarInfo<NAME, BINDING> declare(NAME origName, FilePosition declSite) throws RedeclarationException { VarInfo<NAME, BINDING> d = vars.get(origName); if (d == null) { String newName = nameGenerator.next(); VarInfo<NAME, BINDING> vi = new VarInfo<NAME, BINDING>(origName, newName, declSite); vars.put(origName, vi); return vi; } else { FilePosition dPos = d.declaredAt; throw new RedeclarationException( new Message( RewriterMessageType.CANNOT_REDECLARE_VAR, declSite, MessagePart.Factory.valueOf(origName.toString()), dPos)); } }
@Override public ResourceGroupComposite copyValues(Record from) { Integer idAttrib = from.getAttributeAsInt("id"); String nameAttrib = from.getAttribute(NAME.propertyName()); String descriptionAttrib = from.getAttribute(DESCRIPTION.propertyName()); String typeNameAttrib = from.getAttribute(TYPE.propertyName()); ResourceGroup rg = new ResourceGroup(nameAttrib); rg.setId(idAttrib); rg.setDescription(descriptionAttrib); if (typeNameAttrib != null) { ResourceType rt = new ResourceType(); rt.setName(typeNameAttrib); String pluginNameAttrib = from.getAttribute(PLUGIN.propertyName()); rt.setPlugin(pluginNameAttrib); rg.setResourceType(rt); } Long explicitCount = Long.valueOf(from.getAttribute("explicitCount")); Long explicitDown = Long.valueOf(from.getAttribute("explicitDown")); Long explicitUnknown = Long.valueOf(from.getAttribute("explicitUnknown")); Long explicitDisabled = Long.valueOf(from.getAttribute("explicitDisabled")); Long implicitCount = Long.valueOf(from.getAttribute("implicitCount")); Long implicitDown = Long.valueOf(from.getAttribute("implicitDown")); Long implicitUnknown = Long.valueOf(from.getAttribute("implicitUnknown")); Long implicitDisabled = Long.valueOf(from.getAttribute("implicitDisabled")); ResourceGroupComposite composite = new ResourceGroupComposite( explicitCount, explicitDown, explicitUnknown, explicitDisabled, implicitCount, implicitDown, implicitUnknown, implicitDisabled, rg); return composite; }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); final String name = NAME.validateOperation(operation).asString(); ModelNode variables = model.get(JvmAttributes.JVM_ENV_VARIABLES); if (variables.isDefined()) { final ModelNode values = variables.clone(); model.get(JvmAttributes.JVM_ENV_VARIABLES).setEmptyList(); for (Property value : values.asPropertyList()) { if (!value.getName().equals(name)) { model.get(JvmAttributes.JVM_ENV_VARIABLES).add(value.getName(), value.getValue()); } } } context.stepCompleted(); }
private void emitAttributeValueWrittenNotification( OperationContext context, PathAddress address, String attributeName, ModelNode oldValue, ModelNode newValue) { // only emit a notification if the value has been successfully changed if (oldValue.equals(newValue)) { return; } ModelNode data = new ModelNode(); data.get(NAME.getName()).set(attributeName); data.get(GlobalNotifications.OLD_VALUE).set(oldValue); data.get(GlobalNotifications.NEW_VALUE).set(newValue); Notification notification = new Notification( ATTRIBUTE_VALUE_WRITTEN_NOTIFICATION, address, ControllerLogger.ROOT_LOGGER.attributeValueWritten(attributeName, oldValue, newValue), data); context.emit(notification); }
public void initialize() { venv = new Table(); tenv = new Table(); NAME nameint = new NAME(Symbol.symbol("int")); nameint.bind(new INT()); tenv.put(nameint.name, nameint); NAME namestring = new NAME(Symbol.symbol("string")); namestring.bind(new STRING()); tenv.put(namestring.name, namestring); NAME namenil = new NAME(Symbol.symbol("nil")); namenil.bind(new NIL()); tenv.put(namenil.name, namenil); Symbol print = Symbol.symbol("print"); RECORD printargu = new RECORD(Symbol.symbol("s"), newstring, null); venv.put( print, new FunEntry( new Level(Semant.globalLevZero, print, new BoolList(true, null)), new Label(), printargu, newvoid, true)); Symbol printi = Symbol.symbol("printi"); RECORD printiargu = new RECORD(Symbol.symbol("i"), newint, null); venv.put( printi, new FunEntry( new Level(Semant.globalLevZero, printi, new BoolList(true, null)), new Label(), printiargu, newvoid, true)); Symbol flush = Symbol.symbol("flush"); RECORD flushargu = null; venv.put( flush, new FunEntry( new Level(Semant.globalLevZero, flush, null), new Label(), flushargu, newvoid, true)); Symbol getchar = Symbol.symbol("getchar"); RECORD getcharargu = null; venv.put( getchar, new FunEntry( new Level(Semant.globalLevZero, getchar, null), new Label(), getcharargu, newstring, true)); Symbol ord = Symbol.symbol("ord"); RECORD ordargu = new RECORD(Symbol.symbol("s"), newstring, null); venv.put( ord, new FunEntry( new Level(Semant.globalLevZero, ord, new BoolList(true, null)), new Label(), ordargu, newint, true)); Symbol chr = Symbol.symbol("chr"); RECORD chrargu = new RECORD(Symbol.symbol("i"), newint, null); venv.put( chr, new FunEntry( new Level(Semant.globalLevZero, chr, new BoolList(true, null)), new Label(), chrargu, newstring, true)); Symbol size = Symbol.symbol("size"); RECORD sizeargu = new RECORD(Symbol.symbol("s"), newstring, null); venv.put( size, new FunEntry( new Level(Semant.globalLevZero, size, new BoolList(true, null)), new Label(), sizeargu, newint, true)); Symbol substring = Symbol.symbol("substring"); RECORD substringargu3 = new RECORD(Symbol.symbol("n"), newint, null); RECORD substringargu2 = new RECORD(Symbol.symbol("first"), newint, substringargu3); RECORD substringargu1 = new RECORD(Symbol.symbol("s"), newstring, substringargu2); RECORD substringargu = substringargu1; venv.put( substring, new FunEntry( new Level( Semant.globalLevZero, substring, new BoolList(true, new BoolList(true, new BoolList(true, null)))), new Label(), substringargu, newstring, true)); Symbol concat = Symbol.symbol("concat"); RECORD concatargu2 = new RECORD(Symbol.symbol("s2"), newstring, null); RECORD concatargu1 = new RECORD(Symbol.symbol("s1"), newstring, concatargu2); RECORD concatargu = concatargu1; venv.put( concat, new FunEntry( new Level(Semant.globalLevZero, concat, new BoolList(true, new BoolList(true, null))), new Label(), concatargu, newstring, true)); Symbol not = Symbol.symbol("not"); RECORD notargu = new RECORD(Symbol.symbol("i"), newint, null); venv.put( not, new FunEntry( new Level(Semant.globalLevZero, not, new BoolList(true, null)), new Label(), notargu, newint, true)); Symbol exit = Symbol.symbol("exit"); RECORD exitargu = new RECORD(Symbol.symbol("i"), newint, null); venv.put( exit, new FunEntry( new Level(Semant.globalLevZero, exit, new BoolList(true, null)), new Label(), exitargu, newvoid, true)); }
@Override public SiteSet deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Builder builder = Site.builder(); // check if we have a site list if (json.isJsonArray()) { Type type = new TypeToken<List<Site>>() {}.getType(); List<Site> sites = context.deserialize(json, type); return new SiteSet(sites); } // or a region JsonObject jRegion = json.getAsJsonObject().getAsJsonObject(REGION); if (jRegion.has(VS30.toString())) { double vs30 = jRegion.get(VS30.toString()).getAsDouble(); builder.vs30(vs30); } if (jRegion.has(VS_INF.toString())) { boolean vsInf = jRegion.get(VS_INF.toString()).getAsBoolean(); builder.vsInferred(vsInf); } if (jRegion.has(Z1P0.toString())) { double z1p0 = jRegion.get(Z1P0.toString()).getAsDouble(); builder.z1p0(z1p0); } if (jRegion.has(Z2P5.toString())) { double z2p5 = jRegion.get(Z2P5.toString()).getAsDouble(); builder.z2p5(z2p5); } checkState(jRegion.has(BORDER), "Site region must define a border"); checkState(jRegion.has(SPACING), "Site region must define a spacing"); String name = "Unnamed region"; if (jRegion.has(NAME.toString())) { name = jRegion.get(NAME.toString()).getAsString(); } double spacing = jRegion.get(SPACING).getAsDouble(); JsonArray coords = jRegion.getAsJsonArray(BORDER); LocationList.Builder borderBuilder = LocationList.builder(); for (JsonElement jElem : coords) { JsonArray coord = jElem.getAsJsonArray(); borderBuilder.add(coord.get(1).getAsDouble(), coord.get(0).getAsDouble()); } LocationList border = borderBuilder.build(); checkState(border.size() >= 2, "Site region border must define at " + "least 2 coordinates"); GriddedRegion region = (border.size() == 2) ? Regions.createRectangularGridded( name, border.get(0), border.get(1), spacing, spacing, GriddedRegion.ANCHOR_0_0) : Regions.createGridded( name, border, MERCATOR_LINEAR, spacing, spacing, GriddedRegion.ANCHOR_0_0); return new SiteSet(region, builder); }
public static AttributeDefinition[] getReadOnlyAttributeDefinitions() { return new AttributeDefinition[] {NAME.getAttribute()}; }
/** * Given the input stream, read a document * * @since solr 1.3 */ public SolrInputDocument readDoc(XMLStreamReader parser) throws XMLStreamException { SolrInputDocument doc = new SolrInputDocument(); String attrName = ""; for (int i = 0; i < parser.getAttributeCount(); i++) { attrName = parser.getAttributeLocalName(i); if ("boost".equals(attrName)) { doc.setDocumentBoost(Float.parseFloat(parser.getAttributeValue(i))); } else { log.warn("XML element <doc> has invalid XML attr:" + attrName); } } StringBuilder text = new StringBuilder(); String name = null; float boost = 1.0f; boolean isNull = false; String update = null; Collection<SolrInputDocument> subDocs = null; Map<String, Map<String, Object>> updateMap = null; boolean complete = false; while (!complete) { int event = parser.next(); switch (event) { // Add everything to the text case XMLStreamConstants.SPACE: case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: text.append(parser.getText()); break; case XMLStreamConstants.END_ELEMENT: if ("doc".equals(parser.getLocalName())) { if (subDocs != null && !subDocs.isEmpty()) { doc.addChildDocuments(subDocs); subDocs = null; } complete = true; break; } else if ("field".equals(parser.getLocalName())) { // should I warn in some text has been found too Object v = isNull ? null : text.toString(); if (update != null) { if (updateMap == null) updateMap = new HashMap<>(); Map<String, Object> extendedValues = updateMap.get(name); if (extendedValues == null) { extendedValues = new HashMap<>(1); updateMap.put(name, extendedValues); } Object val = extendedValues.get(update); if (val == null) { extendedValues.put(update, v); } else { // multiple val are present if (val instanceof List) { List list = (List) val; list.add(v); } else { List<Object> values = new ArrayList<>(); values.add(val); values.add(v); extendedValues.put(update, values); } } break; } doc.addField(name, v, boost); boost = 1.0f; // field is over name = null; } break; case XMLStreamConstants.START_ELEMENT: text.setLength(0); String localName = parser.getLocalName(); if ("doc".equals(localName)) { if (subDocs == null) subDocs = Lists.newArrayList(); subDocs.add(readDoc(parser)); } else { if (!"field".equals(localName)) { String msg = "XML element <doc> has invalid XML child element: " + localName; log.warn(msg); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, msg); } boost = 1.0f; update = null; isNull = false; String attrVal = ""; for (int i = 0; i < parser.getAttributeCount(); i++) { attrName = parser.getAttributeLocalName(i); attrVal = parser.getAttributeValue(i); if (NAME.equals(attrName)) { name = attrVal; } else if ("boost".equals(attrName)) { boost = Float.parseFloat(attrVal); } else if ("null".equals(attrName)) { isNull = StrUtils.parseBoolean(attrVal); } else if ("update".equals(attrName)) { update = attrVal; } else { log.warn("XML element <field> has invalid XML attr: " + attrName); } } } break; } } if (updateMap != null) { for (Map.Entry<String, Map<String, Object>> entry : updateMap.entrySet()) { name = entry.getKey(); Map<String, Object> value = entry.getValue(); doc.addField(name, value, 1.0f); } } return doc; }
@Override public boolean matches(final String page, final String parameters) { return NAME.equals(page) && (!StringUtils.isEmpty(parameters) && parameters.contains(DocumentPageMode.PERSONREFERENCES.toString())); }
/** Tests if exception is thrown when we try to save without mandatory properties */ @Test public void createInvalidTest() throws CompanyServiceValidationException { Company company = new Company(); Owner o = new Owner(); o.setCompany(company); // test missing companyid try { companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), COMPANYID.toString()); } // test missing address try { company.setCompanyId("1"); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), ADDRESS.toString()); } // test missing city try { company.setAddress(PREFIX_ADDRESS); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), CITY.toString()); } // test missing country try { company.setCity(PREFIX_CITY); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), COUNTRY.toString()); } // test missing name try { company.setCountry(PREFIX_COUNTRY); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), NAME.toString()); } // test if at least 1 owner is added try { company.setName(PREFIX_NAME); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_OWNER); } // test missing owner firstname try { company.getOwners().add(o); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), OWNER_FIRSTNAME.toString()); } // test missing owner lastname try { o.setFirstName(PREFIX_FIRSTNAME); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), MISSING_FIELD); assertEquals(e.getInfo(), OWNER_LASTNAME.toString()); } // just save o.setLastName(PREFIX_LASTNAME); companyService.save(company); final String INVALID = "invalid"; // test invalid phone try { company.setPhone(INVALID); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), INVALID_PHONE_NUMBER); } // test invalid email try { company.setPhone(null); company.setEmail(INVALID); companyService.save(company); } catch (CompanyServiceValidationException e) { assertEquals(e.getError(), INVALID_EMAIL); } }
Component workspaceLink(String id, final IModel<WorkspaceInfo> itemModel) { IModel<?> nameModel = NAME.getModel(itemModel); return new SimpleBookmarkableLink( id, WorkspaceEditPage.class, nameModel, "name", (String) nameModel.getObject()); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { NAME.validateOperation(operation); final ModelNode nameModel = GlobalOperationAttributes.NAME.resolveModelAttribute(context, operation); final PathAddress address = context.getCurrentAddress(); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); if (registry == null) { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noSuchResourceType(address)); } final boolean useEnhancedSyntax = containsEnhancedSyntax(nameModel.asString(), registry); final String attributeName; final String attributeExpression; if (useEnhancedSyntax) { attributeExpression = nameModel.asString(); attributeName = extractAttributeName(nameModel.asString()); } else { attributeName = nameModel.asString(); attributeExpression = attributeName; } final AttributeAccess attributeAccess = registry.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); if (attributeAccess == null) { throw new OperationFailedException( ControllerLogger.ROOT_LOGGER.unknownAttribute(attributeName)); } else if (attributeAccess.getAccessType() != AttributeAccess.AccessType.READ_WRITE) { throw new OperationFailedException( ControllerLogger.ROOT_LOGGER.attributeNotWritable(attributeName)); } else { // Authorize ModelNode currentValue; if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION) { ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); currentValue = model.has(attributeName) ? model.get(attributeName) : new ModelNode(); } else { currentValue = new ModelNode(); } AuthorizationResult authorizationResult = context.authorize(operation, attributeName, currentValue); if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) { throw ControllerLogger.ROOT_LOGGER.unauthorized( operation.require(OP).asString(), address, authorizationResult.getExplanation()); } if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION && !registry.isRuntimeOnly()) { // if the attribute is stored in the configuration, we can read its // old and new value from the resource's model before and after executing its write handler final ModelNode oldValue = currentValue.clone(); doExecuteInternal( context, operation, attributeAccess, attributeName, currentValue, useEnhancedSyntax, attributeExpression); ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode newValue = model.has(attributeName) ? model.get(attributeName) : new ModelNode(); emitAttributeValueWrittenNotification(context, address, attributeName, oldValue, newValue); } else { assert attributeAccess.getStorageType() == AttributeAccess.Storage.RUNTIME; // if the attribute is a runtime attribute, its old and new values must // be read using the attribute's read handler and the write operation // must be sandwiched between the 2 calls to the read handler. // Each call to the read handlers will have their own results while // the call to the write handler will use this OSH context result. OperationContext.Stage currentStage = context.getCurrentStage(); final ModelNode readAttributeOperation = Util.createOperation(READ_ATTRIBUTE_OPERATION, address); readAttributeOperation.get(NAME.getName()).set(attributeName); ReadAttributeHandler readAttributeHandler = new ReadAttributeHandler(null, null, false); // create 2 model nodes to store the result of the read-attribute operations // before and after writing the value final ModelNode oldValue = new ModelNode(); final ModelNode newValue = new ModelNode(); // We're going to add a bunch of steps, but we want them to execute right away // so we use the 'addFirst=true' param to addStep. That means we add them // in reverse order of how they will execute // 4th OSH is to emit the notification context.addStep( new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // aggregate data from the 2 read-attribute operations emitAttributeValueWrittenNotification( context, address, attributeName, oldValue.get(RESULT), newValue.get(RESULT)); } }, currentStage, true); // 3rd OSH is to read the new value context.addStep(newValue, readAttributeOperation, readAttributeHandler, currentStage, true); // 2nd OSH is to write the value context.addStep( new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { doExecuteInternal( context, operation, attributeAccess, attributeName, oldValue.get(RESULT), useEnhancedSyntax, attributeExpression); } }, currentStage, true); // 1st OSH is to read the old value context.addStep(oldValue, readAttributeOperation, readAttributeHandler, currentStage, true); } } }