@Override public ResponseEntity<List<MgmtDistributionSetType>> createDistributionSetTypes( @RequestBody final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) { final List<DistributionSetType> createdSoftwareModules = distributionSetTypeManagement .create(MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes)); return ResponseEntity.status(HttpStatus.CREATED) .body(MgmtDistributionSetTypeMapper.toListResponse(createdSoftwareModules)); }
/** * 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())))); }
/** * 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 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")); } }
@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 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()))); }
@Test @Description("Handles the GET request of retrieving the list of optional software module types in that distribution set type. Required Permission: " + SpPermission.READ_REPOSITORY) public void getOptionalModules() 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}/optionalmoduletypes", 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), fieldWithPath("[]lastModifiedBy") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY), fieldWithPath("[]name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("[]deleted").description(ApiModelPropertiesGeneric.DELETED), fieldWithPath("[]_links.self").ignored()))); }
@Test @Description("Handles the GET request of retrieving the single mandatory software module type in that distribution set type. Required Permission: " + SpPermission.READ_REPOSITORY) public void getMandatoryModule() 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/{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)), 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()))); }