@Override public ResponseEntity<List<MgmtSoftwareModuleMetadata>> createMetadata( @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestBody final List<MgmtSoftwareModuleMetadata> metadataRest) { final List<SoftwareModuleMetadata> created = softwareModuleManagement.createMetaData( MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, softwareModuleId, metadataRest)); return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponseSwMetadata(created)); }
private void addTestModuleMetadata(final SoftwareModule module) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(VISIBLE_SM_MD_KEY).value(VISIBLE_SM_MD_VALUE).targetVisible(true)); softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(INVISIBLE_SM_MD_KEY).value(INVISIBLE_SM_MD_VALUE).targetVisible(false)); }
private void addTestModuleMetadata(final SoftwareModule module) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(VISIBLE_SM_MD_KEY).value(VISIBLE_SM_MD_VALUE).targetVisible(true)); softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(INVISIBLE_SM_MD_KEY).value(INVISIBLE_SM_MD_VALUE).targetVisible(false)); }
@Override protected SoftwareModuleMetadata createMetadata(final SoftwareModule entity, final String key, final String value) { final SoftwareModuleMetadata swMetadata = softwareModuleManagement .createMetaData(entityFactory.softwareModuleMetadata().create(entity.getId()).key(key).value(value) .targetVisible(targetVisibleField.getValue())); setSelectedEntity(swMetadata.getSoftwareModule()); return swMetadata; }
@Override protected SoftwareModuleMetadata createMetadata(final SoftwareModule entity, final String key, final String value) { final SoftwareModuleMetadata swMetadata = softwareModuleManagement .createMetaData(entityFactory.softwareModuleMetadata().create(entity.getId()).key(key).value(value) .targetVisible(targetVisibleField.getValue())); setSelectedEntity(swMetadata.getSoftwareModule()); return swMetadata; }
@Test @Description(" Update a single meta data value for speficic key." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void putMetadata() throws Exception { // prepare and create metadata for update final String knownKey = "knownKey"; final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue) .put("targetVisible", true); mockMvc.perform( put(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}", module.getId(), knownKey).contentType(MediaTypes.HAL_JSON_UTF8).content(jsonObject.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters(parameterWithName("softwareModuleId") .description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("metadataKey").description(MgmtApiModelProperties.META_DATA_KEY)), requestFields(requestFieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), requestFieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE), requestFieldWithPath("targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)))); }
@Test @Description(" Delete a single meta data." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void deleteMetadata() throws Exception { // prepare and create metadata for deletion final String knownKey = "knownKey"; final String knownValue = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue)); mockMvc.perform(delete( MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{{metadataKey}", module.getId(), knownKey)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("{metadataKey").description(MgmtApiModelProperties.META_DATA_KEY)))); }
@Test @Description(" Get a single meta data value for a meta data key." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadataValue() throws Exception { // prepare and create metadata final String knownKey = "knownKey"; final String knownValue = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue)); mockMvc.perform( get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}", module.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("metadataKey").description(MgmtApiModelProperties.META_DATA_KEY)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)))); }
@Test @Description(" Get a paged list of meta data for a software module." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadata() throws Exception { final int totalMetadata = 4; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); for (int index = 0; index < totalMetadata; index++) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(knownKeyPrefix + index).value(knownValuePrefix + index)); } mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata", module.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8)) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS), fieldWithPath("size").type(JsonFieldType.NUMBER) .description(ApiModelPropertiesGeneric.SIZE), fieldWithPath("content").description(MgmtApiModelProperties.META_DATA), fieldWithPath("content[].key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("content[].value").description(MgmtApiModelProperties.META_DATA_VALUE), fieldWithPath("content[].targetVisible") .description(MgmtApiModelProperties.SM_META_DATA_TARGET_VISIBLE)))); }
@Test @Description(" Get a paged list of meta data for a software module with defined page size and sorting by name descending and key starting with 'known'." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadataWithParameters() throws Exception { final int totalMetadata = 4; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get(); for (int index = 0; index < totalMetadata; index++) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(knownKeyPrefix + index).value(knownValuePrefix + index)); } mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata", module.getId()).param("offset", "1").param("limit", "2").param("sort", "key:DESC").param("q", "key==known*")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8)) .andDo(this.document.document( pathParameters( parameterWithName("softwareModuleId").description(ApiModelPropertiesGeneric.ITEM_ID)), requestParameters( parameterWithName("limit").attributes(key("type").value("query")) .description(ApiModelPropertiesGeneric.LIMIT), parameterWithName("sort").description(ApiModelPropertiesGeneric.SORT), parameterWithName("offset").description(ApiModelPropertiesGeneric.OFFSET), parameterWithName("q").description(ApiModelPropertiesGeneric.FIQL)))); }
}); softwareModuleManagement.createMetaData( entityFactory.softwareModuleMetadata().create(set.getModules().iterator().next().getId()) .key("aMetadataKey").value("Metadata value as defined in software module").targetVisible(true));