static List<MetaData> fromRequestDsMetadata(final List<MgmtMetadata> metadata, final EntityFactory entityFactory) { if (metadata == null) { return Collections.emptyList(); } return metadata.stream() .map(metadataRest -> entityFactory.generateDsMetadata(metadataRest.getKey(), metadataRest.getValue())) .collect(Collectors.toList()); }
@Override public ResponseEntity<MgmtMetadata> updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadataBodyPut metadata) { // check if distribution set exists otherwise throw exception // immediately final DistributionSetMetadata updated = distributionSetManagement.updateMetaData(distributionSetId, entityFactory.generateDsMetadata(metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated)); }
@Override protected DistributionSetMetadata createMetadata(final DistributionSet entity, final String key, final String value) { final DistributionSetMetadata dsMetaData = distributionSetManagement .createMetaData(entity.getId(), Collections.singletonList(entityFactory.generateDsMetadata(key, value))) .get(0); setSelectedEntity(dsMetaData.getDistributionSet()); return dsMetaData; }
@Override protected DistributionSetMetadata createMetadata(final DistributionSet entity, final String key, final String value) { final DistributionSetMetadata dsMetaData = distributionSetManagement .createMetaData(entity.getId(), Collections.singletonList(entityFactory.generateDsMetadata(key, value))) .get(0); setSelectedEntity(dsMetaData.getDistributionSet()); return dsMetaData; }
@Override protected DistributionSetMetadata updateMetadata(final DistributionSet entity, final String key, final String value) { final DistributionSetMetadata dsMetaData = distributionSetManagement.updateMetaData(entity.getId(), entityFactory.generateDsMetadata(key, value)); setSelectedEntity(dsMetaData.getDistributionSet()); return dsMetaData; }
@Override protected DistributionSetMetadata updateMetadata(final DistributionSet entity, final String key, final String value) { final DistributionSetMetadata dsMetaData = distributionSetManagement.updateMetaData(entity.getId(), entityFactory.generateDsMetadata(key, value)); setSelectedEntity(dsMetaData.getDistributionSet()); return dsMetaData; }
@Test @Description("Update a single meta data value for speficic key." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY) public void updateMetadata() throws Exception { // prepare and create metadata for update final String knownKey = "knownKey"; final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; final DistributionSet testDS = testdataFactory.createDistributionSet("one"); distributionSetManagement.createMetaData(testDS.getId(), Arrays.asList(entityFactory.generateDsMetadata(knownKey, knownValue))); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); mockMvc.perform(put( MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata/{metadatakey}", testDS.getId(), knownKey).contentType(MediaType.APPLICATION_JSON_UTF8).content(jsonObject.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters( parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("metadatakey").description(ApiModelPropertiesGeneric.ITEM_ID)), requestFields(requestFieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), requestFieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE)))); }
@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 DistributionSet testDS = testdataFactory.createDistributionSet("one"); distributionSetManagement.createMetaData(testDS.getId(), Arrays.asList(entityFactory.generateDsMetadata(knownKey, knownValue))); mockMvc.perform( delete(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata/{key}", testDS.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("key").description(ApiModelPropertiesGeneric.ITEM_ID)))); }
@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 DistributionSet testDS = testdataFactory.createDistributionSet("one"); distributionSetManagement.createMetaData(testDS.getId(), Arrays.asList(entityFactory.generateDsMetadata(knownKey, knownValue))); mockMvc.perform(get( MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata/{metadatakey}", testDS.getId(), knownKey)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters( parameterWithName("distributionSetId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("metadatakey").description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY), fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE)))); }
@Test @Description("Get a paged list of meta data for a distribution set with standard page size." + " Required Permission: " + SpPermission.READ_REPOSITORY) public void getMetadata() throws Exception { final int totalMetadata = 4; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; final DistributionSet testDS = testdataFactory.createDistributionSet("one"); for (int index = 0; index < totalMetadata; index++) { distributionSetManagement.createMetaData(testDS.getId(), Lists .newArrayList(entityFactory.generateDsMetadata(knownKeyPrefix + index, knownValuePrefix + index))); } mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata", testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON_UTF8)) .andDo(this.document.document( pathParameters( parameterWithName("distributionSetId").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)))); }
@Test @Description("Get a paged list of meta data for a distribution set 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 DistributionSet testDS = testdataFactory.createDistributionSet("one"); for (int index = 0; index < totalMetadata; index++) { distributionSetManagement.createMetaData(testDS.getId(), Lists .newArrayList(entityFactory.generateDsMetadata(knownKeyPrefix + index, knownValuePrefix + index))); } mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{dsId}/metadata", testDS.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( 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)), 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)))); }