@Override public String serializeToString() { StringBuilder str = new StringBuilder(); return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", voId=<").append(getVoId()).append(">").append( ", facilityId=<").append(getFacilityId()).append(">").append( ", name=<").append(getName() == null ? "\\0" : BeansUtils.createEscaping(getName())).append(">").append( ", description=<").append(getDescription() == null ? "\\0" : BeansUtils.createEscaping(getDescription())).append(">").append( ']').toString(); }
private static Resource createResource(Map<String, String> beanAttr) { if(beanAttr==null) return null; Resource resource = new Resource(); resource.setId(Integer.valueOf(beanAttr.get("id"))); resource.setVoId(Integer.valueOf(beanAttr.get("voId"))); resource.setFacilityId(Integer.valueOf(beanAttr.get("facilityId"))); resource.setName(BeansUtils.eraseEscaping(beanAttr.get("name"))); resource.setDescription(BeansUtils.eraseEscaping(beanAttr.get("description"))); return resource; }
/** * Constructs a new instance. */ public RichResource(Resource resource) { super(resource.getId(), resource.getName(), resource.getDescription(), resource.getFacilityId(), resource.getVoId(), resource.getCreatedAt(), resource.getCreatedBy(), resource.getModifiedAt(), resource.getModifiedBy(), resource.getCreatedByUid(), resource.getModifiedByUid()); }
@Override public int compareTo(PerunBean perunBean) { if(perunBean == null) throw new NullPointerException("PerunBean to compare with is null."); if(perunBean instanceof Resource) { Resource resource = (Resource) perunBean; if (this.getName() == null && resource.getName() != null) return -1; if (resource.getName() == null && this.getName() != null) return 1; if (this.getName() == null && resource.getName() == null) return 0; return this.getName().compareToIgnoreCase(resource.getName()); } else { return (this.getId() - perunBean.getId()); } } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Resource other = (Resource) obj; if (this.getId() != other.getId()) { return false; } if (this.name == null ? other.getName() != null : !this.name.equals(other.getName())) { return false; } if (this.description == null ? other.getDescription() != null : !this.description.equals(other.getDescription())) { return false; } return true; }
public void deleteResource(Resource resource) throws InternalErrorException { try { ldapTemplate.unbind(getResourceDN(String.valueOf(resource.getVoId()), String.valueOf(resource.getId()))); log.debug("Entry deleted from LDAP: Resource {} from Vo with ID=" + resource.getVoId() + " and Facility with ID=" + resource.getFacilityId() + ".", resource); } catch (NameNotFoundException e) { throw new InternalErrorException(e); } }
result.add(facility); Resource resource = new Resource(); resource.setId(0); resource.setName("ServicesManagerTestResource"); resource.setDescription("testovaci"); result.add(resource);
@Override public String toString() { StringBuilder str = new StringBuilder(); return str.append(getClass().getSimpleName()).append(":[id='").append(getId() ).append("', voId='").append(voId ).append("', facilityId='").append(facilityId ).append("', name='").append(name ).append("', description='").append(description).append("']").toString(); }
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); String tags = "\\0"; if (getResourceTags() != null && !getResourceTags().isEmpty()) { ArrayList<String> list = new ArrayList<String>(); for (ResourceTag t : getResourceTags()) { list.add(t.serializeToString()); } tags = list.toString(); } return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", voId=<").append(getVoId()).append(">").append( ", facilityId=<").append(getFacilityId()).append(">").append( ", name=<").append(super.getName() == null ? "\\0" : BeansUtils.createEscaping(super.getName())).append(">").append( ", description=<").append(super.getDescription() == null ? "\\0" : BeansUtils.createEscaping(super.getDescription())).append(">").append( ", facility=<").append(getFacility() == null ? "\\0" : getFacility().serializeToString()).append(">").append( ", vo=<").append(getVo() == null ? "\\0" : getVo().serializeToString()).append(">").append( ", resourceTags=<").append(tags).append(">").append( ']').toString(); }
public ResourceExistsException(Resource resource) { super("Resource with name \"" + resource.getName() + "\" already exists in Facility and Vo."); this.resource = resource; }
public boolean resourceAttributeExist(Resource resource, String ldapAttributeName) throws InternalErrorException { if(ldapAttributeName == null) throw new InternalErrorException("ldapAttributeName can't be null."); Object o = null; try { setLdapAttributeName(ldapAttributeName); o = ldapTemplate.lookup(getResourceDN(String.valueOf(resource.getVoId()), String.valueOf(resource.getId())), new AttributeContextMapper()); } catch (NameNotFoundException ex) { return false; } if(o == null) return false; return true; }
public static Facility getFacility(RpcCaller rpcCaller, Resource resource) throws InternalErrorException, ResourceNotExistsException, PrivilegeException { Map<String, Object> params = new HashMap<String, Object>(); params.put("resource", resource.getId()); try { return rpcCaller.call("resourcesManager", "getFacility", params).read(Facility.class); } catch (ResourceNotExistsException e) { throw e; } catch (PrivilegeException e) { throw e; } catch (InternalErrorException e) { throw e; } catch (PerunException e) { throw new ConsistencyErrorException(e); } }
@Override public String toString() { StringBuilder str = new StringBuilder(); return str.append(getClass().getSimpleName()).append(":[" ).append("id='").append(getId() ).append("', voId='").append(super.getVoId() ).append("', facilityId='").append(super.getFacilityId() ).append("', name='").append(super.getName() ).append("', description='").append(super.getDescription() ).append("', facility='").append(getFacility() ).append("', vo='").append(getVo() ).append("', resourceTags='").append(getResourceTags() ).append("']").toString(); }
public static List<Service> getAssignedServices(RpcCaller rpcCaller, Resource resource) throws InternalErrorException, ResourceNotExistsException, PrivilegeException { Map<String, Object> params = new HashMap<String, Object>(); params.put("resource", resource.getId()); try { return rpcCaller.call("resourcesManager", "getAssignedServices", params).readList(Service.class); } catch (ResourceNotExistsException e) { throw e; } catch (PrivilegeException e) { throw e; } catch (InternalErrorException e) { throw e; } catch (PerunException e) { throw new ConsistencyErrorException(e); } }
public void createResource(Resource resource, String entityID) throws InternalErrorException { // Create a set of attributes Attributes attributes = new BasicAttributes(); // Create the objectclass to add Attribute objClasses = new BasicAttribute(EventProcessorImpl.ldapAttrObjectClass); objClasses.add(EventProcessorImpl.objectClassTop); objClasses.add(EventProcessorImpl.objectClassPerunResource); // Add attributes attributes.put(objClasses); attributes.put(EventProcessorImpl.ldapAttrCommonName, resource.getName()); attributes.put(EventProcessorImpl.ldapAttrPerunResourceId, String.valueOf(resource.getId())); attributes.put(EventProcessorImpl.ldapAttrPerunFacilityId, String.valueOf(resource.getFacilityId())); attributes.put(EventProcessorImpl.ldapAttrPerunVoId, String.valueOf(resource.getVoId())); if(resource.getDescription() != null && !resource.getDescription().isEmpty()) attributes.put(EventProcessorImpl.ldapAttrDescription, resource.getDescription()); // get info about entityID attribute if exists if(entityID != null) attributes.put(EventProcessorImpl.ldapAttrEntityID, entityID); // Create the entry try { ldapTemplate.bind(getResourceDN(String.valueOf(resource.getVoId()), String.valueOf(resource.getId())), null, attributes); log.debug("New entry created in LDAP: Resource {} in Vo with Id=" + resource.getVoId() + " and Facility with ID=" + resource.getFacilityId() + ".", resource); } catch (NameNotFoundException e) { throw new InternalErrorException(e); } }
associatedResources = perun.getResourcesManagerBl().getAssignedResources(perunSession, group); for(Resource r: associatedResources) { writer.write("assignedToResourceId: " + r.getId()); writer.write('\n');
Facility facility = null; try { facility = perun.getFacilitiesManagerBl().getFacilityById(perunSession, resource.getFacilityId()); } catch (FacilityNotExistsException ex) { throw new InternalErrorException("Can't found facility of this resource " + resource, ex); dn+= "perunResourceId=" + resource.getId() + ",perunVoId=" + resource.getVoId() + "," + ldapBase; writer.write(dn + '\n'); cn+= resource.getName(); writer.write(cn + '\n'); perunVoId+= String.valueOf(resource.getVoId()); writer.write(perunVoId + '\n'); perunFacilityId+= String.valueOf(resource.getFacilityId()); writer.write(perunFacilityId + '\n'); perunResourceId+= String.valueOf(resource.getId()); writer.write(perunResourceId + '\n'); String descriptionValue = resource.getDescription(); if(descriptionValue != null) { if(descriptionValue.matches("^\\s*$")) descriptionValue = null;
updateGroupAttribute(ldapAttrAssignedToResourceId, String.valueOf(this.resource.getId()), LdapOperation.ADD_ATTRIBUTE, this.group); updateResourceAttribute(ldapAttrAssignedGroupId, String.valueOf(this.group.getId()), LdapOperation.ADD_ATTRIBUTE, this.resource); updateGroupAttribute(ldapAttrAssignedToResourceId, String.valueOf(this.resource.getId()), LdapOperation.REMOVE_ATTRIBUTE, this.group); updateResourceAttribute(ldapAttrAssignedGroupId, String.valueOf(this.group.getId()), LdapOperation.REMOVE_ATTRIBUTE, this.resource); ldapConnector.createResource(resource, getFacilityEntityIdValue(resource.getFacilityId())); replaceList.add(new Pair(ldapAttrCommonName,this.resource.getName())); if(this.resource.getDescription() != null && !this.resource.getDescription().isEmpty()) replaceList.add(new Pair(ldapAttrDescription, this.resource.getDescription())); attributes.put(LdapOperation.REPLACE_ATTRIBUTE, replaceList); updateResourceAttributes(attributes, this.resource);