Commit c0062f1d authored by Christos Tranoris's avatar Christos Tranoris
Browse files

added resources by category

parent 8da3934a
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -435,12 +435,21 @@ public class ResourceSpecificationRepoService {
		resourceSpec.setLastUpdate( OffsetDateTime.now(ZoneOffset.UTC) );
		
		if (resourceSpec instanceof PhysicalResourceSpecification){
		  if ( resSpecUpd instanceof ResourceSpecificationCreate resCreate) {
            ((PhysicalResourceSpecification) resourceSpec)
            .model(( (PhysicalResourceSpecificationCreate)  (ResourceSpecificationUpdate) resCreate ).getModel() )
            .part( ( (PhysicalResourceSpecificationCreate)  (ResourceSpecificationUpdate) resCreate ).getPart())
            .sku( ( (PhysicalResourceSpecificationCreate)   (ResourceSpecificationUpdate) resCreate ).getSku())
            .vendor(( (PhysicalResourceSpecificationCreate)  (ResourceSpecificationUpdate) resCreate ).getVendor() );
		    
		  } else {
            ((PhysicalResourceSpecification) resourceSpec)
            .model(( (PhysicalResourceSpecificationUpdate) resSpecUpd ).getModel() )
            .part( ( (PhysicalResourceSpecificationUpdate) resSpecUpd ).getPart())
            .sku( ( (PhysicalResourceSpecificationUpdate) resSpecUpd ).getSku())
            .vendor(( (PhysicalResourceSpecificationUpdate) resSpecUpd ).getVendor() );		    
		  }
		}
		
		
		if ( resSpecUpd.getLifecycleStatus() != null ) {
+12 −4
Original line number Diff line number Diff line
@@ -58,7 +58,8 @@ public class ResourceApiRouteBuilder extends RouteBuilder {
	@Value("${CATALOG_GET_RESOURCE_BY_ID}")
	private String CATALOG_GET_RESOURCE_BY_ID = "";


	@Value("${CATALOG_GET_RESOURCE_BY_CATEGORY}")
	private String CATALOG_GET_RESOURCE_BY_CATEGORY = "";

	@Value("${CATALOG_RESOURCES_OF_PARTNERS}")
	private String CATALOG_RESOURCES_OF_PARTNERS = "";
@@ -88,6 +89,13 @@ public class ResourceApiRouteBuilder extends RouteBuilder {
		.bean( resourceRepoService, "getResourceEagerAsString")
		.convertBodyTo( String.class );

		from( CATALOG_GET_RESOURCE_BY_CATEGORY )
		.log(LoggingLevel.DEBUG, log, CATALOG_GET_RESOURCE_BY_CATEGORY + " message received!")
		.to("log:DEBUG?showBody=true&showHeaders=true")
		.bean( resourceRepoService, "getResourcesByCategory(${header.category})")
		.marshal().json( JsonLibrary.Jackson)
		.convertBodyTo( String.class );

		from( CATALOG_UPD_RESOURCE )
		.log(LoggingLevel.DEBUG, log, CATALOG_UPD_RESOURCE + " message received!")
		.to("log:DEBUG?showBody=true&showHeaders=true")
+47 −0
Original line number Diff line number Diff line
@@ -200,6 +200,53 @@ public class ResourceRepoService {
    return (List<Resource>) this.resourceRepo.findByRolename(name);
  }

  public List<Map<String, Object>> getResourcesByCategory(String category) {
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();

    try {
      String sql = "SELECT " +
          "srv.uuid as id," +
          "srv.type as type," +
          "srv.name as name," +
          "srv.category as category," +
          "srv.description as description " +
          "FROM RIResource srv " +
          "WHERE srv.category = :category " +
          "ORDER BY srv.name ASC";

      List<Object> result = session.createQuery(sql)
          .setParameter("category", category)
          .setResultTransformer(new ResultTransformer() {
            @Override
            public Object transformTuple(Object[] tuple, String[] aliases) {
              Map<String, Object> result = new LinkedHashMap<String, Object>(tuple.length);
              for (int i = 0; i < tuple.length; i++) {
                String alias = aliases[i];
                if (alias != null) {
                  if (alias.equals("type")) {
                    alias = "@type";
                  }
                  result.put(alias, tuple[i]);
                }
              }
              return result;
            }

            @Override
            public List transformList(List collection) {
              return collection;
            }
          }).list();

      return (List<Map<String, Object>>) (List<?>) result;

    } finally {
      tx.commit();
      session.close();
    }
  }

  @Transactional
  public Resource addResource(@Valid ResourceCreate resource) {
    logger.info("Will add Resource: " + resource.getName());
+1 −0
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ CATALOG_ADD_RESOURCE: "jms:queue:CATALOG.ADD.RESOURCE"
CATALOG_UPD_RESOURCE: "jms:queue:CATALOG.UPD.RESOURCE"
CATALOG_UPDADD_RESOURCE: "jms:queue:CATALOG.UPDADD.RESOURCE"
CATALOG_GET_RESOURCE_BY_ID: "jms:queue:CATALOG.GET.RESOURCE"
CATALOG_GET_RESOURCE_BY_CATEGORY: "jms:queue:CATALOG.GET.RESOURCE_BY_CATEGORY"
CATALOG_ADD_RESOURCESPEC: "jms:queue:CATALOG.ADD.RESOURCESPEC"
CATALOG_UPD_RESOURCESPEC: "jms:queue:CATALOG.UPD.RESOURCESPEC"
CATALOG_UPDADD_RESOURCESPEC: "jms:queue:CATALOG.UPDADD.RESOURCESPEC"
+1 −0
Original line number Diff line number Diff line
@@ -244,6 +244,7 @@ CATALOG_ADD_RESOURCE: "jms:queue:CATALOG.ADD.RESOURCE"
CATALOG_UPD_RESOURCE: "jms:queue:CATALOG.UPD.RESOURCE"
CATALOG_UPDADD_RESOURCE: "jms:queue:CATALOG.UPDADD.RESOURCE"
CATALOG_GET_RESOURCE_BY_ID: "jms:queue:CATALOG.GET.RESOURCE"
CATALOG_GET_RESOURCE_BY_CATEGORY: "jms:queue:CATALOG.GET.RESOURCE_BY_CATEGORY"
CATALOG_ADD_RESOURCESPEC: "jms:queue:CATALOG.ADD.RESOURCESPEC"
CATALOG_UPD_RESOURCESPEC: "jms:queue:CATALOG.UPD.RESOURCESPEC"
CATALOG_UPDADD_RESOURCESPEC: "jms:queue:CATALOG.UPDADD.RESOURCESPEC"