/** * Finds {@link DistributionSetType} in repository with given * {@link DistributionSetType#getKey()} or creates if it does not exist yet. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * @param mandatory * {@link DistributionSetType#getMandatoryModuleTypes()} * @param optional * {@link DistributionSetType#getOptionalModuleTypes()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black") .optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())) .mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())))); }
@Override public ResponseEntity<MgmtDistributionSetType> updateDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) { final DistributionSetType updated = distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(distributionSetTypeId).description(restDistributionSetType.getDescription()) .colour(restDistributionSetType.getColour())); final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(updated); MgmtDistributionSetTypeMapper.addLinks(reponse); return ResponseEntity.ok(reponse); }
/** * Finds {@link DistributionSetType} in repository with given * {@link DistributionSetType#getKey()} or creates if it does not exist yet. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * @param mandatory * {@link DistributionSetType#getMandatoryModuleTypes()} * @param optional * {@link DistributionSetType#getOptionalModuleTypes()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black") .optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())) .mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())))); }
/** * Creates {@link DistributionSetType} in repository. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black"))); }
/** * Creates {@link DistributionSetType} in repository. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black"))); }
@SuppressWarnings("unchecked") private void updateDistributionSetType(final DistributionSetType existingType) { final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); final DistributionSetTypeUpdate update = getEntityFactory().distributionSetType().update(existingType.getId()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview())); if (distributionSetManagement.countByTypeId(existingType.getId()) <= 0 && !CollectionUtils.isEmpty(itemIds)) { update.mandatory(itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList())) .optional(itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList())); } final DistributionSetType updateDistSetType = getDistributionSetTypeManagement().update(update); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", updateDistSetType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.UPDATE_DIST_SET_TYPE, updateDistSetType)); }
@SuppressWarnings("unchecked") private void updateDistributionSetType(final DistributionSetType existingType) { final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); final DistributionSetTypeUpdate update = getEntityFactory().distributionSetType().update(existingType.getId()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview())); if (distributionSetManagement.countByTypeId(existingType.getId()) <= 0 && !CollectionUtils.isEmpty(itemIds)) { update.mandatory(itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList())) .optional(itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList())); } final DistributionSetType updateDistSetType = getDistributionSetTypeManagement().update(update); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", updateDistSetType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.UPDATE_DIST_SET_TYPE, updateDistSetType)); }
@SuppressWarnings("unchecked") private void createNewDistributionSetType() { final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()); final String typeNameValue = getTagName().getValue(); final String typeKeyValue = getTypeKey().getValue(); final String typeDescValue = getTagDesc().getValue(); final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); if (typeNameValue != null && typeKeyValue != null && !CollectionUtils.isEmpty(itemIds)) { final List<Long> mandatory = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final List<Long> optional = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final DistributionSetType newDistType = getDistributionSetTypeManagement() .create(getEntityFactory().distributionSetType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).mandatory(mandatory).optional(optional)); getUiNotification().displaySuccess(getI18n().getMessage("message.save.success", newDistType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.ADD_DIST_SET_TYPE, newDistType)); } else { getUiNotification().displayValidationError(getI18n().getMessage("message.error.missing.typenameorkey")); } }
@SuppressWarnings("unchecked") private void createNewDistributionSetType() { final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()); final String typeNameValue = getTagName().getValue(); final String typeKeyValue = getTypeKey().getValue(); final String typeDescValue = getTagDesc().getValue(); final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); if (typeNameValue != null && typeKeyValue != null && !CollectionUtils.isEmpty(itemIds)) { final List<Long> mandatory = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final List<Long> optional = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final DistributionSetType newDistType = getDistributionSetTypeManagement() .create(getEntityFactory().distributionSetType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).mandatory(mandatory).optional(optional)); getUiNotification().displaySuccess(getI18n().getMessage("message.save.success", newDistType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.ADD_DIST_SET_TYPE, newDistType)); } else { getUiNotification().displayValidationError(getI18n().getMessage("message.error.missing.typenameorkey")); } }
private static DistributionSetTypeCreate fromRequest(final EntityFactory entityFactory, final MgmtDistributionSetTypeRequestBodyPost smsRest) { return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName()) .description(smsRest.getDescription()).colour(smsRest.getColour()) .mandatory(getMandatoryModules(smsRest)).optional(getOptionalmodules(smsRest)); }
@Test @Description("Handles the GET request of retrieving a single distribution set type within SP. Required Permission: READ_REPOSITORY") public void deleteDistributionSetType() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234")); mockMvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}", testType.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)))); }
@Test @Description("Handles the GET request of retrieving all distribution set types within SP with a defined page size and offset, sortet by name in descending order and filtered down to all targets which name starts with 'a'. Required Permission: READ_REPOSITORY.") public void getDistributionSetTypesWithParameters() throws Exception { distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234")); mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON) .param("offset", "1").param("limit", "2").param("sort", "name:DESC").param("q", "name==a*")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(this.document.document(getFilterRequestParamter())); }
@Test @Description("Handles the POST request for adding a mandatory software module type to a distribution set type." + "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: " + SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY) public void postMandatoryModule() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.create( entityFactory.distributionSetType().create().key("test1").name("TestName1").description("Desc1")); mockMvc.perform(post(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}/mandatorymoduletypes", testType.getId()) .content("{\"id\":" + osType.getId() + "}").contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters(parameterWithName("distributionSetTypeId") .description(ApiModelPropertiesGeneric.ITEM_ID)), requestFields(requestFieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID)))); }
@Test @Description("Handles the GET request of retrieving the list of software module types in that distribution set. " + "Note that a DS type cannot be changed after it has been used by a DS. Required permissions: " + SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY) public void deleteMandatoryModule() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("test1").name("TestName1").description("Desc1").mandatory(osType).optional(runtimeType)); mockMvc.perform(delete( MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}/mandatorymoduletypes/{softwareModuleTypeId}", testType.getId(), osType.getId()).contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("softwareModuleTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)))); }
@Test @Description("Handles the POST request for adding an optional software module type to a distribution set type." + "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: " + SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY) public void postOptionalModule() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.create( entityFactory.distributionSetType().create().key("test1").name("TestName1").description("Desc1")); mockMvc.perform(post(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}/optionalmoduletypes", testType.getId()) .content("{\"id\":" + appType.getId() + "}").contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document( pathParameters(parameterWithName("distributionSetTypeId") .description(ApiModelPropertiesGeneric.ITEM_ID)), requestFields(requestFieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID)))); }
@Test @Description("Handles DELETE request for removing an optional module from the distribution set type." + "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: " + SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY) public void deleteOptionalModule() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("test1").name("TestName1").description("Desc1").mandatory(osType).optional(runtimeType)); mockMvc.perform(delete( MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}/optionalmoduletypes/{softwareModuleTypeId}", testType.getId(), appType.getId()).contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("softwareModuleTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)))); }
@Test @Description("Handles the GET request of retrieving all distribution set types within SP. Required Permission: READ_REPOSITORY.") public void getDistributionSetTypes() throws Exception { distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234")); mockMvc.perform( get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.total", equalTo(4))) .andDo(this.document.document(responseFields( fieldWithPath("size").type(JsonFieldType.NUMBER).description(ApiModelPropertiesGeneric.SIZE), fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS), fieldWithPath("content").description(MgmtApiModelProperties.TARGET_LIST), fieldWithPath("content[].createdBy").description(ApiModelPropertiesGeneric.CREATED_BY), fieldWithPath("content[].createdAt").description(ApiModelPropertiesGeneric.CREATED_AT), fieldWithPath("content[].description").description(ApiModelPropertiesGeneric.DESCRPTION), fieldWithPath("content[].key").description(MgmtApiModelProperties.DS_TYPE_KEY), fieldWithPath("content[].id").description(ApiModelPropertiesGeneric.ITEM_ID), fieldWithPath("content[].lastModifiedAt") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"), fieldWithPath("content[].lastModifiedBy") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY).type("String"), fieldWithPath("content[].name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("content[]._links.self").ignored()))); }
@Test @Description("Handles the DELETE request for a single distribution set type within SP. Required Permission: DELETE_REPOSITORY.") public void getDistributionSetType() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(testdataFactory.createDistributionSet().getType().getId()).description("Desc1234")); mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}", testType.getId()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) .andDo(this.document.document( pathParameters(parameterWithName("distributionSetTypeId") .description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY), fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT), fieldWithPath("description").description(ApiModelPropertiesGeneric.DESCRPTION), fieldWithPath("key").description(MgmtApiModelProperties.DS_TYPE_KEY), fieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID), fieldWithPath("lastModifiedAt").description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT) .type("Number"), fieldWithPath("lastModifiedBy").description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY) .type("String"), fieldWithPath("name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("deleted").description(ApiModelPropertiesGeneric.DELETED), fieldWithPath("_links.self").ignored(), fieldWithPath("_links.mandatorymodules") .description(MgmtApiModelProperties.LINK_TO_MANDATORY_SMT), fieldWithPath("_links.optionalmodules") .description(MgmtApiModelProperties.LINK_TO_OPTIONAL_SMT)))); }
@Test @Description("Handles the GET request of retrieving the single optional software module type in that distribution set type. Required Permission: " + SpPermission.READ_REPOSITORY) public void getOptionalModule() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("test1").name("TestName1").description("Desc1").mandatory(osType).optional(appType)); mockMvc.perform(get( MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}/optionalmoduletypes/{softwareModuleTypeId}", testType.getId(), appType.getId()).contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("distributionSetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID), parameterWithName("softwareModuleTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY), fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT), fieldWithPath("description").description(ApiModelPropertiesGeneric.DESCRPTION), fieldWithPath("key").description(MgmtApiModelProperties.SM_TYPE_KEY), fieldWithPath("maxAssignments").description(MgmtApiModelProperties.SMT_MAX_ASSIGNMENTS), fieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID), fieldWithPath("lastModifiedAt").description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT) .type("Number"), fieldWithPath("lastModifiedBy").description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY) .type("String"), fieldWithPath("name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("deleted").description(ApiModelPropertiesGeneric.DELETED), fieldWithPath("_links.self").ignored()))); }
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Handles the GET request of retrieving the list of mandatory software module types in that distribution set type. Required Permission: READ_REPOSITORY.") public void getMandatoryModules() throws Exception { final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key("test1").name("TestName1").description("Desc1").mandatory(osType).optional(runtimeType)); mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/{distributionSetTypeId}/mandatorymoduletypes", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andDo(this.document.document( pathParameters(parameterWithName("distributionSetTypeId") .description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("[]createdBy").description(ApiModelPropertiesGeneric.CREATED_BY), fieldWithPath("[]createdAt").description(ApiModelPropertiesGeneric.CREATED_AT), fieldWithPath("[]description").description(ApiModelPropertiesGeneric.DESCRPTION), fieldWithPath("[]key").description(MgmtApiModelProperties.SM_TYPE_KEY), fieldWithPath("[]maxAssignments") .description(MgmtApiModelProperties.SMT_MAX_ASSIGNMENTS), fieldWithPath("[]id").description(ApiModelPropertiesGeneric.ITEM_ID), fieldWithPath("[]lastModifiedAt") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"), fieldWithPath("[]lastModifiedBy") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY).type("String"), fieldWithPath("[]name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("[]deleted").description(ApiModelPropertiesGeneric.DELETED), fieldWithPath("[]_links.self").ignored()))); }