Search in sources :

Example 16 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class FacilitySoftwareController method queryFacilitySoftwareConfigByPage.

@RequestMapping(value = "/page/{pageNumber}/pagesize/{pageSize}", method = RequestMethod.GET)
public Page<FacilitySoftwareConfig> queryFacilitySoftwareConfigByPage(@PathVariable("pageNumber") int currentPage, @PathVariable("pageSize") int pageSize, HttpServletRequest request, @RequestParam(required = false) SoftwareType[] softwaretypes) {
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    if (currentPage < FlowgateConstant.defaultPageNumber) {
        currentPage = FlowgateConstant.defaultPageNumber;
    } else if (pageSize <= 0) {
        pageSize = FlowgateConstant.defaultPageSize;
    } else if (pageSize > FlowgateConstant.maxPageSize) {
        pageSize = FlowgateConstant.maxPageSize;
    }
    PageRequest pageRequest = PageRequest.of(currentPage - 1, pageSize);
    Optional<WormholeUser> currentUserOptional = userRepository.findById(user.getUserId());
    WormholeUser currentUser = currentUserOptional.get();
    Page<FacilitySoftwareConfig> result = null;
    List<String> types = new ArrayList<String>();
    if (softwaretypes != null && softwaretypes.length > 0) {
        for (SoftwareType type : softwaretypes) {
            types.add(type.name());
        }
    }
    if (currentUser.getRoleNames().contains(FlowgateConstant.Role_admin)) {
        if (types.isEmpty()) {
            result = repository.findAll(pageRequest);
        } else {
            result = repository.findAllByTypeIn(types, pageRequest);
        }
    } else {
        if (types.isEmpty()) {
            result = repository.findALlByUserId(user.getUserId(), pageRequest);
        } else {
            result = repository.findAllByUserIdAndTypeIn(user.getUserId(), types, pageRequest);
        }
    }
    if (result != null) {
        for (FacilitySoftwareConfig facilitySoftwareConfig : result.getContent()) {
            facilitySoftwareConfig.setPassword(null);
        }
    }
    return result;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) SoftwareType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class FacilitySoftwareController method getInternalFacilitySoftwareConfigByID.

@RequestMapping(value = "/internal/{id}", method = RequestMethod.GET)
public FacilitySoftwareConfig getInternalFacilitySoftwareConfigByID(@PathVariable String id) {
    Optional<FacilitySoftwareConfig> serverOptional = repository.findById(id);
    FacilitySoftwareConfig server = serverOptional.get();
    decryptServerPassword(server);
    return server;
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class AggregatorServiceTest method getFacilitySoftware.

private ResponseEntity<FacilitySoftwareConfig[]> getFacilitySoftware() {
    FacilitySoftwareConfig[] facilitySoftwareConfigs = new FacilitySoftwareConfig[1];
    FacilitySoftwareConfig facilitySoftwareConfig = new FacilitySoftwareConfig();
    facilitySoftwareConfig.setId("QWENBADJWRTUIJWJAYQY");
    facilitySoftwareConfig.setPassword("O75xginpkAD748w=Lc20CrTzd1lEpvDTdJqH5IXBZTb5gYp7P8awDAs19F0=");
    facilitySoftwareConfig.setServerURL("https://10.161.71.133");
    facilitySoftwareConfig.setName("powerIQ-1");
    facilitySoftwareConfig.setVerifyCert(false);
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setRetryCounter(0);
    integrationStatus.setDetail("");
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    facilitySoftwareConfig.setIntegrationStatus(integrationStatus);
    facilitySoftwareConfig.setUserName("admin");
    facilitySoftwareConfig.setType(FacilitySoftwareConfig.SoftwareType.PowerIQ);
    facilitySoftwareConfig.setUserId("e1edfv8953002379827896a1aaiqoose");
    facilitySoftwareConfigs[0] = facilitySoftwareConfig;
    return new ResponseEntity<>(facilitySoftwareConfigs, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

Example 19 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class MessageProcessingTest method testExecuteCustomerSendMessageJob2.

@Test
public void testExecuteCustomerSendMessageJob2() throws JobExecutionException {
    FacilitySoftwareConfig fac1 = createFacilitySoftware();
    String unique_value1 = UUID.randomUUID().toString();
    fac1.setSubCategory("OtherDCIM_" + unique_value1);
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherDCIM)).thenReturn(getFacilitySoftwareByType(fac1));
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherCMDB)).thenReturn(new ResponseEntity<FacilitySoftwareConfig[]>(new FacilitySoftwareConfig[0], HttpStatus.OK));
    FacilityAdapter adapter = new FacilityAdapter();
    adapter.setSubCategory("OtherDCIM_" + unique_value1);
    AdapterJobCommand command1 = new AdapterJobCommand();
    command1.setCommand("syncmetadata");
    command1.setTriggerCycle(20);
    List<AdapterJobCommand> commands = new ArrayList<AdapterJobCommand>();
    commands.add(command1);
    adapter.setCommands(commands);
    adapter.setTopic(unique_value1);
    adapter.setQueueName(unique_value1 + ":joblist");
    FacilityAdapter[] adapters = new FacilityAdapter[1];
    adapters[0] = adapter;
    when(restClient.getAllCustomerFacilityAdapters()).thenReturn(new ResponseEntity<FacilityAdapter[]>(new FacilityAdapter[0], HttpStatus.OK));
    customerAdapter.execute(null);
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 20 with FacilitySoftwareConfig

use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.

the class MessageProcessingTest method testExecuteCustomerSendMessageJob3.

@Test
public void testExecuteCustomerSendMessageJob3() throws JobExecutionException {
    ListOperations<String, String> listOp = Mockito.mock(ListOperations.class);
    ValueOperations<String, String> valueOp = Mockito.mock(ValueOperations.class);
    when(template.opsForList()).thenReturn(listOp);
    when(listOp.leftPushAll(anyString(), anyString())).thenReturn(1L);
    when(template.hasKey(anyString())).thenReturn(true);
    when(template.opsForValue()).thenReturn(valueOp);
    when(valueOp.increment(anyString())).thenReturn(4l);
    FacilitySoftwareConfig fac1 = createFacilitySoftware();
    String unique_value1 = UUID.randomUUID().toString();
    fac1.setSubCategory("OtherDCIM_" + unique_value1);
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherDCIM)).thenReturn(new ResponseEntity<FacilitySoftwareConfig[]>(new FacilitySoftwareConfig[0], HttpStatus.OK));
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherCMDB)).thenReturn(new ResponseEntity<FacilitySoftwareConfig[]>(new FacilitySoftwareConfig[0], HttpStatus.OK));
    FacilityAdapter adapter = new FacilityAdapter();
    adapter.setSubCategory("OtherDCIM_" + unique_value1);
    AdapterJobCommand command1 = new AdapterJobCommand();
    command1.setCommand("syncmetadata");
    command1.setTriggerCycle(20);
    List<AdapterJobCommand> commands = new ArrayList<AdapterJobCommand>();
    commands.add(command1);
    adapter.setCommands(commands);
    adapter.setTopic(unique_value1);
    adapter.setQueueName(unique_value1 + ":joblist");
    FacilityAdapter[] adapters = new FacilityAdapter[1];
    adapters[0] = adapter;
    when(restClient.getAllCustomerFacilityAdapters()).thenReturn(new ResponseEntity<FacilityAdapter[]>(adapters, HttpStatus.OK));
    customerAdapter.execute(null);
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)60 Test (org.junit.Test)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)29 ArrayList (java.util.ArrayList)13 Asset (com.vmware.flowgate.common.model.Asset)8 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)7 IOException (java.io.IOException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)6 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)5 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)5 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)5 HashMap (java.util.HashMap)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)4 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)4 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)4